# -+- number -+- category -+- title -+- email -+- name -+- homepage -+- clickOnName -+- language -+- image -+- browser-used -+- security-cookie
=0 -+- 2000-02-14:5 -+- UNIX Basics -+- Colors in the command prompt -+- guido.s@writeme.com -+- Guido Socher -+- -+- email -+- English -+- 2000-02-14:5.gif -+- Mozilla/4.7 [en] (X11; I; Linux 2.2.10 i586; Nav) -+- 3326
All terminal windows for Linux understand Ansi color codes
and with these codes it is possible to have colors in the shell prompt.
The color codes are:
This command prints e.g Linux in yellow on a red background:
/bin/echo '\033[41;33;1m Linux \033[m'
Just try it out copying the command into the next shell.
To insert special characters such as (a literal Esc) into the shell prompt you must include them in %{ %} for tcsh and \[ \] for bash
This gives e.g the tcsh prompt that you can see in the picture above:
set prompt='%{^[[44;33;1m%}%!\-%n@%m%{^[[m%} \n%{^[[44;37;1m%}(%~)%#%{^[[m%} '
A yellow prompt for bash is e.g:
PS1='\[^[[40;33;1m\]\u@\h:\w\$\[^[[m\] '
In both cases the literal Esc character is shown as ^[. Note: You can not
copy and paste these lines from the web browser to the shell. To get a literal
Esc in Vi you type crtl-v Esc and in Emacs this is crtl-q Esc.
Happy color command prompts!