There's already a lot of guides out there about how to adjust your bash prompt. So this article is mostly for me to have easy access to my personal prefered prompt, no matter at which computer I am. But maybe it's useful for you as well.
Before we start ...
The setup is slightly different depending on what you are working with. I'm usually using one of two setups: Arch Linux or Windows with Gitbash. So I'll be explaining those two in this article.
The prompt is saved in the variable
PS1. The configuration goes into
~/.bashrc. To configure any styling, you need to put the desired command in escaped brackets:
To set a font color, use the command
\e[xxm, with xx being one of the following numbers:
- 30 - black
- 31 - red
- 32 - green
- 33 - yellow
- 34 - blue
- 35 - magenta
- 36 - cyan
- 37 - light grey
- 39 - default
- 90 - dark grey
- 91 - light red
- 92 - light green
- 93 - light yellow
- 94 - light blue
- 95 - light magenta
- 96 - light cyan
- 97 - white
To set a background color, choose the desired color from above and add 10 to the color value.
Here are some other commands, that may be useful:
- # \e[0m - reset all
- # \e[1m \e[21m - bold / no bold
- # \e[4m \e[24m - underline / no underline
- # \e[7m \e[27m - invert / no invert
In Linux I have the following script. What's to look out for? To display the current git branch (if any), the required command is
$(__git_ps1 "%s"). It's possible to put some other characters around the
%s for styling. However, this is not set initially, so first it's necessary to check and (if available) load git. There has been some refactoring so there should be one of two possible versions for the script, either
git-completion.bash. Just check for both.
This prompt configuration will look like this:
Windows with Gitbash
There's not as much to configure for Gitbash as for bash in Linux.
__git_ps1 is already loaded. Unfortunately, it works a little different on Windows Gitbash. It needs to be accessed like this:
`__git_ps1` and it returns something like this:
(master), including the parenthesis.