extra-prompt.sh

taipan67 sysadm.taipan67 at btinternet.com
Sun Jul 29 03:23:23 PDT 2007


Bruce Dubbs wrote:
> David Jensen wrote:
>   
>> Moving to dev. 
>>     
>
>   
>> Ag. D. Hatzimanikas wrote:
>>     
>>> Does this prompt (in /etc/profile) looks good to you? (it was suggested by 
>>> David Jensen)
>>>
>>> if [[ ${EUID} == 0 ]] ; then
>>> 	PS1='\[\e[1;31m\]\u [ \[\e[00m\]\w \[\e[1;31m\]]\$ \[\e[00m\]'
>>>         else
>>> 	PS1='\[\e[1;32m\]\u [ \[\e[00m\]\w \[\e[1;32m\]]\$ \[\e[00m\]'
>>> fi
>>>       
>
> This is too cryptic.  Use:
>
> NORMAL="\[\033[0;39m\]"
> RED="\[\033[1;31m\]"
> GREEN="\[\033[1;32m\]"
>
> if [[ ${EUID} == 0 ]] ; then
>   PS1="$RED\u [ $NORMAL\w$RED ]\$ $NORMAL"
> else
>   PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
> fi
>
>   -- Bruce
>   
I've also stolen coloured PS1 values from my current Gentoo-box, & they 
use the '\033' escape-sequence listed above, but in full, not through 
variable-names. They also define 'normal' as "\[\033[00m\]" (not sure of 
the difference).

However, Gentoo define them in /etc/bashrc, & have the line ". 
/etc/bashrc" (that's 'full-stop' 'space' 'filename') in /etc/profile, 
instead of a PS1 declaration. I found this to be necessary when booting 
into my LFS system. I also have a third colour defined for 
package-users, but that had to go in the pkgusr ~/.bashrc to work, 
presumably because they never boot the system, they are only su'd to by 
root.

There are additional pre-checks for the existence of /etc/dircolors & 
that the terminal in use supports colour. For future builds, it's my 
intention to incorporate this into my base LFS-build, as dircolors is 
installed by coreutils fairly early in both chapters 5 & 6 - i haven't 
worked out the details yet...

taipan




More information about the blfs-dev mailing list