There is an excellent reference page describing how to colourize your bash prompt on the Arch Linux wiki.
It includes information about the colours, escape sequences and the correct way to include other characters or to print information in the prompt, such as the directory, host, etc.
As an example, a simple prompt like:
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
Can be broken down into these elements:
\[\e[1;32m]
- an opening square bracket printed in green (1;32m)
[\u@h \W]
- username@hostname and the basename of the current working directory
\$
- the prompt (a #
if the UID is 0)
\[e[0m\]
- the text reset escape signalling the end of the colour sequence.
Using these sequences, you can build up a colourful, informative prompt.
A word of caution: if you fail to correctly escape sequences, you can wreak havoc with your terminal's ability to print text.
force_color_prompt=yes
in.bashrc
, or run the terminal withTERM=xterm-color
. – alex Jul 06 '11 at 07:13