Bash Color Shell Prompt
You can customize 4 prompts: PS1 (Primary prompt, displayed before each command), PS2 (secondary prompt, displayed when a command needs more input), PS3 (rarely used, displayed for Bash’s select built-in which displays interactive menus).
Display current bash prompt (PS1) settings:
echo $PS1
Output: [\u@\h \W]\$
It is the default setting. The backslash-escaped characters means: \u (username), \h (hostname), \W (current working directory).
To modify colors to the prompt use following syntax:
\e[x;ym $PS1 \e[m
Meaning: \e[ (start color scheme), x;y (color pair to use), $PS1 (shell prompt variable), \e[m (stop color scheme)
To set red color enter:
export PS1="\e[0;36m[\u@\h \W]\$ \e[m "
Few examples of color codes:
- black(0;30)
- red (0;31)
- greed (0;32)
- brown (0;33)
- blue (0;34)
- purple (0:35)
- cyan (0:36)
If you replace digit 0 with 1 you get a lighter color version.
Setting variable PS1 is temporary, when you log out your settings will be lost. You have to append the following line to $HOME/.bash_profile file or $HOME/.bashrc file:
export PS1="\e[0;36m[\u@\h \W]\$ \e[m "
Now ur new prompt color is permanent.