This guide shows you how to configure your Bash prompt on Ubuntu (and derivatives) to display:
- Username@Host in bold green
- Current directory in bold blue
- Git branch in bold yellow
- Ubuntu or compatible Linux distribution
- Git installed
bash-completion
package (to source Git’s prompt helper)
sudo apt update
sudo apt install bash-completion
Add this to your ~/.bashrc
:
# enable Git branch info
if [ -f /usr/share/git/completion/git-prompt.sh ]; then
source /usr/share/git/completion/git-prompt.sh
fi
Append this line to the same ~/.bashrc
:
export PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0m\]\$ '
What the codes mean:
\e[1;32m
→ bold green (user@host)\e[1;34m
→ bold blue (current directory)\e[1;33m
→ bold yellow (git branch)\e[0m
→ reset
source ~/.bashrc
When you open a terminal, it’ll look like this:
user@device:/path/to/dir (branch-name)$
With each part colored and bold, as defined in the PS1 string.