Coloring the Terminal prompt

Along with being the file to store your Terminal aliases, ~/.profile also allows you to color the Terminal prompt. This article has the particulars: BASH Shell change the color of my shell prompt under Linux or UNIX

First take a look at the current prompt with echo $PS1. It should return with \h:\W \u\$ . The articles above detail what those variables represent, and it translates to host:directory username$. Color syntax starts with [\e[0;31m\] and ends with \[\e[m\]. The color code itself is 0:31, where 31 is the color (in this case red) and 0 being the equivalent of font-weight (bold is 1).

I am currently rocking:

export PS1="\[\e[0;31m\]\h:\[\e[m\]\[\e[0;34m\]\W\[\e[m\] \[\e[0;30m\]\u\[\e[m\]\[\e[0;33m\]\$\[\e[m\] "

Which is the same host:directory username$ but now red:blue darkgray and a beige $.

Colored BASH Terminal

UPDATE 16 Nov 2010 Revised opening and closing tags to \[\e[0;31m\] and \[\e[m\]. Previous version didn’t close tags properly and messed up line breaks. Removed link to erroneous article.