A Bold Prompt in Bash
Posted: February 12th, 2006 Tags: HowtoI wanted my Bash prompt to be bold and red so I could find my one line of input amongst the million lines of output in my terminal. I’m no Unix nerd, so I don’t really know offhand where to look for this info. After a bunch of Googling, I found something that works for me. The shell variable for the prompt is naturally called PS1. The original value was:
PS1='\\h:\\w \\u\\$ '
The code for starting a font and color change is \\e[. The code for bold red is 1;31. The code for closing the starting code for a font and color tag is m. The closing code for a font and color change is \\e[m. Bash thinks that these color commands will increase the length of the prompt, which will cause odd line wrapping behavior. The solution is to wrap all the color codes in brackets (\\[ and \\]).
So, the entire prompt looks like this:
PS1='\\[\\e[1;31m\\]\\h:\\w \\u\\$\\[\\e[m\\] ‘
Eeech. Add that to your .bashrc file and you’re all set. If you don’t want the red, the prompt would be:
PS1='\\[\\e[1m\\]\\h:\\w \\u\\$\\[\\e[m\\] ‘
More colors are listed at the bottom of this page.