You are looking to change the ANSI escape sequences, specifically the colors.
\e[...m
takes a semicolon-separate list of codes to manipulate how the following text is displayed. 33
represents yellow foreground text, 1
represents bold text, 31
represents red foreground text, and 0 resets all values (foreground and background colors, styles, etc) to their terminal defaults.
# Make text yellow and bold, then make it red (keeping it bold)
# and finally restore the default
PS1='\e[33;1m\u@\h: \e[31m\W\e[0m\$'
To use green/white instead of yellow/red, change 33 to 32 and 31 to 37. Also, be sure to enclose characters that do not take up any space on screen inside \[...\]
so that the shell can properly determine the length of your prompt.
PS1='\[\e[32;1m\]\u@\h: \[\e[37m\]\W\[\e[0m\]\$'
This assumes that your terminal understands ANSI escape sequences; a more portable method is to use tput
to output the codes your actual terminal uses:
PS1='\[$(tput bold; tput setaf 2)\u@\h: \[$(tput setaf y)\]\W$(tput sgr0)\$ '
zsh
, incidentally, makes this much easier; it has built-in escapes for changing the color in a terminal-independent way:
# 1. Everything between %B and %b is in bold
# 2. Everything between %F{x} and %f is in a different color;
# x can be a color name, and you can switch from one
# color to another without using %f
# 3. zsh is smart enough to account for built-in escapes when
# computing the prompt lenght, so no equivalent of \[...\]
# is needed
# 4. %n is the same as \u
# 5. %m is the same as \h
# 6. %~ is roughly the same as \W
# 7. %# is roughly the same as \$
PS1='%B%F{green}%n@%m: %F{white}%~%b%f%# '