[GLLUG] bash madness

Matt Graham danceswithcrows@usa.net
Fri, 19 Jul 2002 16:29:50 -0400


On Friday 19 July 2002 15:51, after a long battle with technology, Ben 
Pfaff wrote:
[snippage]
> About prompts: I use
>         PS1='\u@\h:\w($?)\$ '
> because I like to see who I am logged in as, the host I'm logged
> into, the current directory, and the exit code of the last
> command I ran.

This is a good general solution, but the \u makes the prompt longer than 
it needs to be in lots of cases, particularly when you're really deep 
in a directory tree.  For the machines where I'm the only person who 
has root, I put this in ~root/.bashrc :

PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '

...making the shell prompt show up in red in root shells, providing a 
great visual cue that reminds me to double-check each command line 
before hitting Return.

For those machines where I'm not the only person who has root, I put 
this in ~root/.bashrc :

MGPS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '

...so all the other users don't go "huh?" when they see a prompt they 
aren't expecting, and all I have to do to get a familiar prompt is 
"export PS1=$MGPS1" after su'ing.

(I *really* don't like the default Redhat prompt that uses \W instead of 
\w and puts useless []s in PS1.  \W I can almost see the reasons for, 
the brackets seem totally silly.)

-- 
   Jesus is the best radio producer in the beans.  We need some saliva
   and pickles to get mad.   --MegaHAL, "The Best of MegaHAL"
There is no Darkness in Eternity/But only Light too dim for us to see