Colorized Bash-Prompt

by on under Technical
1 minute read

Having used Gentoo for several years, I’ve been accustomed to colorful console prompts. A colorized prompt is not only beautiful, but also makes it much easier to see the start and end of commands. Without further ado, here is my colorized bash prompt on a CentOS machine:


The root user gets a red and normal users a green prompt. Notice the (master) entry. This is the branch of the git repository located in the current directory.

This prompt is generated by the file /etc/profile.d/

export GIT_PS1_SHOWDIRTYSTATE=true # Symbols: unstaged (*) and staged (+)
export GIT_PS1_SHOWSTASHSTATE=true # Symbol: $
export GIT_PS1_SHOWUNTRACKEDFILES=true # Symbol: %

if [[ ${EUID} == 0 ]]; then
PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W\[\033[01;35m\]$(declare -F __git_ps1 &>/dev/null && __git_ps1 " (%s)") \[\033[01;34m\]\$\[\033[00m\] '
PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \W\[\033[01;35m\]$(declare -F __git_ps1 &>/dev/null && __git_ps1 " (%s)") \[\033[01;34m\]\$\[\033[00m\] '
Gentoo, git, CentOS, Bash