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

10,523

Solution 1

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

Solution 2

Try this one. It is simpler:

export PS1="\e[0;32m\t \e[32;1m\u@\h:\e[0;36m\w\e[0m$ "
Share:
10,523
dylanized
Author by

dylanized

Updated on June 07, 2022

Comments

  • dylanized
    dylanized about 2 years

    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?

  • dylanized
    dylanized about 11 years
    I understand that. However I'm trying to change the "input text" color to something different than the foreground. Probably not a way to do that, but figured i'd ask :)
  • Paul Morris
    Paul Morris almost 5 years
    This doesn't seem to do anything when I add it to my bash_profile
  • dlink
    dlink almost 5 years
    What shell are you using? (echo $SHELL). This only works for bash. Also you can try typing it directly on the command line.