Can I change the input color of my Bash prompt to something different than the terminal default?
Solution 1
Simply add the following line:
export PS1=" \[\033[34m\]\u@\h \[\033[33m\]\w\[\033[31m\]\[\033[00m\] $ "
Preview:
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$ "
dylanized
Updated on June 07, 2022Comments
-
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 about 11 yearsI 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 almost 5 yearsThis doesn't seem to do anything when I add it to my bash_profile
-
dlink almost 5 yearsWhat shell are you using? (echo $SHELL). This only works for bash. Also you can try typing it directly on the command line.