[Techtalk] Console Prompt Colors

Almut Behrens almut-behrens at gmx.net
Sat Apr 24 20:27:51 EST 2004


On Sat, Apr 24, 2004 at 12:26:18PM -0400, Beth Johnson wrote:
> I have a question related to the ls --colors question asked recently. 
> On my Gentoo system when I'm at the console as my usual user the
> username part of the prompt is green, and when I su to root, the
> username part of the prompt changes to red.  I *like* this feature a
> bunch and would like to see it implemented on my desktop system (Fedora
> Core 1).
> 
> Any clues about this?  Is is a profile function or a shell attribute, or
> what?

In my .bashrc I have the following:

export PS1=$'\\e[32m\\u@\\h\\e[m:\\e[34m\\w\\e[m \\$ '

which gives me two different colors for 'user at host' (the \\e[32m part)
and the current directory (the \\e[34m ). The rest is black.
Looks something like (but in color):

almut at tux:~/tmp $
 
See section 'PROMPTING' in the bash manpage for details.
For the color escape sequences there's a seperate manpage, usually
named 'console_codes' or 'console_code' (if it's still something else
on you system, man -k will probably locate it...). Look for section
'Set Graphics Rendition'.

Sample color escape sequences are:

red:   \\e[31m
green: \\e[32m
blue:  \\e[34m
black: \\e[m

The \\u, \\h stand for user, host, etc...

Cheers,
Almut
 



More information about the Techtalk mailing list