Coloring Bash Prompt

Coloring bash prompt is pretty easy. You just have to basically learn the basic color codes.

Now to add colors to bash. Open your terminal and enter the code below.

nano ~/.bashrc

Press CTRL+W and type force_color_prompt. Uncomment that line if its still commented and it should look like force_color_prompt=yes. Continue scrolling and stop when you found the first PS1 like this:

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

Now you can add colors after:

${debian_chroot:+($debian_chroot)}, \u, @, \h, :, \w,

and \$. Note, before you add color codes from above list, be sure to put it inside \[\] and to prevent errors, you must put \[\] first before the color codes. For instance \u\[COLORCODEHERE\]. To assist you with this, follow the line below or copy it and then put color codes (ex: \e[1;32m). If you wish to use variables like Green for example, you must copy the list above and paste it from the very first line of your .bashrc file.

PS1='${debian_chroot:+($debian_chroot)}\[\]\u\[\]@\[\]\h\[\]:\[\]\w\[\]\$ \[\]'
# OR


PS1='${debian_chroot:+($debian_chroot)}\[\e[0;33m\]\u\[\e[0;37m\]@\[\e[0;36m\]\h\[\033[00m\]:\[\033[01;37m\]\w\[\e[0;31m\]\n\$ \[\033[00m\]'

My bash prompt.

my bash prompt

Useful links: