LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-12-2007, 08:31 PM   #1
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Rep: Reputation: 38
Prompt not hard returning after PS1 variable change?


I created this script for my .bashrc file, to reshape my prompt:
Code:
# User specific aliases and functions

#Colors:
#Black       0;30     Dark Gray     1;30
#Blue        0;34     Light Blue    1;34
#Green       0;32     Light Green   1;32
#Cyan        0;36     Light Cyan    1;36
#Red         0;31     Light Red     1;31
#Purple      0;35     Light Purple  1;35
#Brown       0;33     Yellow        1;33
#Light Gray  0;37     White         1;37

PROMPTCOLOR='\e[1;37m'
COMMANDCOLOR='\e[0;37m'
USERNAMECOLOR='\e[1;32m'
PS1="${USERNAMECOLOR}\u${PROMPTCOLOR} [\w] >${COMMANDCOLOR} "
It works well, but I apparently have a side-effect, in that if I type a command longer than the width of the screen, it seems to fail to do a hard return, overwriting the current line. What did I mess up?

P.S. I really like this script. It works well for me. I set up my root script so it shows in red, which reminds me of my current user state.
 
Old 04-12-2007, 09:12 PM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Just to be sure we are seeing an anomaly with your script, do you see the same side-effect if you don't run the prompt change in your .bashrc?
 
Old 04-13-2007, 07:51 PM   #3
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Original Poster
Rep: Reputation: 38
Yes, it is. Here is a display with the default PS1:
Code:
[geoff@localhost ~]$ lfkjsdlfkjsdlfksdjflsdkfjsdlfkjsdf lksdjf lsdkjf sdlkfj sdlkfj sldkfj sdlkfj sdlkjf
And here is the display with my modified PS1:
Code:
 kdff [~] > sldkfj sdlkfj sdlkfjsdflksjd flskdjf sldklsdkfj
Thank you for your time.
 
Old 04-20-2007, 07:12 AM   #4
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Original Poster
Rep: Reputation: 38
bump ...
Anyone?
 
Old 05-01-2007, 12:06 PM   #5
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Original Poster
Rep: Reputation: 38
bump ... again ... hoping for some answer ...

I've narrowed it down to the color variables, and not the PS1 prompt directly. I removed all references to the color variables from the PS1 variable, and the problem went away. I tried each color variable in turn, and the problem returns. I also tried adding the ;00 (null) to the prompt, but that doesn't do anything helpful.

I really like my prompt configuration, but I would like to get rid of this one side-effect.
 
Old 05-01-2007, 09:16 PM   #6
SlowCoder
Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Fedora (Desktop), CentOS (Server), Knoppix (Diags)
Posts: 934

Original Poster
Rep: Reputation: 38
Ok, I'll admit it, I feel good. I figured it out ... all by myself, and without y'all's help!

I figured out that bash determines the text wrap based on the length of the PS1 variable. So I had to add \[ and \] to nonvisible/special codes, which included the color codes.

This is my code so far, and I plan to extend it further:
Code:
#Color Codes:
#Black       0;30     Dark Gray     1;30
#Red         0;31     Light Red     1;31
#Green       0;32     Light Green   1;32
#Brown       0;33     Yellow        1;33
#Blue        0;34     Light Blue    1;34
#Purple      0;35     Light Purple  1;35
#Cyan        0;36     Light Cyan    1;36
#Light Gray  0;37     White         1;37

PROMPTCOLOR='\[\e[1;37m\]'
COMMANDCOLOR='\[\e[0;37m\]'
ROOTCOLOR='\[\e[1;31m\]'
NORMALUSERCOLOR='\[\e[1;32m\]'
HOSTNAMECOLOR='\[\e[1;35m\]'
DIRECTORYCOLOR='\[\e[1;33m\]'

### username ###
if [ 'whoami' = 'root' ]
        then USERCOLOR=$ROOTCOLOR
        else USERCOLOR=$NORMALUSERCOLOR
fi
PS1=$USERCOLOR"\u"

### hostname ###
PS1=$PS1$PROMPTCOLOR@
PS1=$PS1$HOSTNAMECOLOR$(hostname -s)

### working directory ###
PS1=$PS1$PROMPTCOLOR" ["
PS1=$PS1$DIRECTORYCOLOR"\w"
PS1=$PS1$PROMPTCOLOR"]"

### prompt end marker ###
PS1=$PS1$USERCOLOR" \$ "

### command color ###
PS1=$PS1$COMMANDCOLOR
I would be happy to receive positive criticism on my script, whether to tell me how to make it better, or to tell me how much you like it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Post your BASH prompt [PS1]? introuble General 11 12-27-2006 03:47 PM
Why does Debian host decide to ignore PS1 variable? Daws Linux From Scratch 2 06-13-2006 07:02 PM
$PS1 different in X and prompt codec Slackware 7 06-27-2004 04:42 PM
PS1 variable wogga Red Hat 2 05-26-2004 05:39 PM
setting the PS1 enviroment variable in xterm schatoor Linux - General 2 04-29-2003 08:41 AM


All times are GMT -5. The time now is 10:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration