See this answer on the Unix & Linux SE. There are a number of additional colors that can be used in a 256 color terminal.
You can view the colors in Terminal, and see their codes, by running this bash script. (There is a also a color chart in the above linked post, or IMO a more readable chart here.)
#!/bin/bash
color=16;
while [ $color -lt 245 ]; do
echo -e "$color: \\033[38;5;${color}mhello\\033[48;5;${color}mworld\\033[0m"
((color++));
done
Once you determine the colors you want, and have the color codes, you can use them in a PS1 prompt like shown below.
48;5;#
where # is the color number you want, sets the background color.
38;5;#
again # replaced with the color number, sets the foreground color.
In my case I wanted the default background that Terminal set when it was launched, and I use 0
to note this. (You can also see that toward the end of the sequence \[\e[0m\]
- same idea, using 0 to reset everything to the default.)
export PS1='\[\e[0;38;5;166m\]\u@\H\[\e[0m\] \w $ '
The below screenshot shows my original, default prompt, and then how it looks when I sourced .bash_profile
after defining PS1
:
