Hack 38. Change background color of the prompt

Change the background color by specifying \e[{code}m in the PS1 prompt as shown below.

$ export PS1="\e[47m\u@\h \w> \e[m "

[Note: This is for Light Gray background]

Combination of background and foreground.

$ export PS1="\e[0;34m\e[47m\u@\h \w> \e[m "

[Note: This is for Light Blue foreground and Light Gray background]

Add the following to your ~/.bash_profile or ~/.bashrc to make the above background and foreground color permanent.

$ vi ~/.bash_profile
STARTFGCOLOR='\e[0;34m';
STARTBGCOLOR="\e[47m"
ENDCOLOR="\e[0m"
export PS1="$STARTFGCOLOR$STARTBGCOLOR\u@\h \w> $ENDCOLOR"

Play around by using the following background color and choose the one that match your taste:

  • \e[40m
  • \e[41m
  • \e[42m
  • \e[43m
  • \e[44m
  • \e[45m
  • \e[46m
  • \e[47m