Can I change the input color of my Bash prompt to something different than the terminal default?

dylanized picture dylanized · May 19, 2013 · Viewed 9.8k times · Source

My default terminal color is gray, and that's fine.

My Bash prompt displays a bunch of colors, and this works fine:

PS1="${COLOR_RED}\u${COLOR_WHITE}@${COLOR_RED}${COMPUTERNAME} ${COLOR_BLUE}\w${GITPROMPT} ${COLOR_RESET}"

But the text I type in, at the end of the prompt, is gray. I want it to be white (ANSI code "[37m").

If I add a COLOR_WHITE at the end of the prompt, instead of the COLOR_RESET, then the default terminal color changes to white until it is reset. This makes a weird effect of some gray text, with some white text bleeding through at the top.

How can I change the "input text" color of the Bash prompt, to something other than the terminal default color?

Answer

Shayan Amani picture Shayan Amani · Jan 11, 2018

Simply add the following line:

export PS1=" \[\033[34m\]\u@\h \[\033[33m\]\w\[\033[31m\]\[\033[00m\] $ "

Preview:

Enter image description here

These are my preferred colors. You can customize each part of the prompt's color by changing m codes (e.g., 34m) which are ANSI color codes.

List of ANSI color codes:

  • Black: 30m
  • Red: 31m
  • Green: 32m
  • Yellow: 33m
  • Blue: 34m
  • Purple: 35m
  • Cyan: 36m
  • White: 37m