[Gllug] Coloured bash prompt

Richard Cohen richard at vmlinuz.org
Wed Apr 21 13:07:44 UTC 2004


On Wed, 21 Apr 2004, Dylan wrote:

> Hi All,
>
> I'm looking to get the bash prompt coloured (so I can pick out the
> commands issued in a screenfull of gumpf.) Obviously, I need to put
> something in $PS1, between /[ and /] I figure - but what? where can I
> find the relevant info?

Being too lazy to look it all up, I can't tell you that...  but I can tell
you that mine is (with comments added):
#setup colours
COLOR1="\[\033[0;36m\]"
COLOR2="\[\033[0;32m\]"
COLOR3="\[\033[0;36m\]"
COLOR4="\[\033[0;37m\]"
#if we're root, use a different colour
if [ "$UID" = "0" ];
then
                COLOR2="\[\033[0;31m\]"
fi
#set the prompt
PS1="$COLOR2($COLOR3\u@\h$COLOR2)-($COLOR1\t$COLOR2 $COLOR1\d$COLOR2)-($COLOR1\W$COLOR2)$COLOR1\n$COLOR1\\$ $COLOR4"
#if we're in an xterm, put the current path, username and machine in the title bar
if [ "$TERM" = "xterm" -o "$TERM" = "xterm-color" -o "$TERM" = "xterms" ];
then
        PROMPT_COMMAND='echo -ne "\033]0;${PWD}  <${USER}@${HOSTNAME}>\007"'
        export PROMPT_COMMAND
fi

> Cheers
> Dylan

Cheers
Richard
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list