Skip to content

Instantly share code, notes, and snippets.

@brenes
Forked from afgomez/colorize_git_ps1.bash
Created June 14, 2011 13:51
Show Gist options
  • Select an option

  • Save brenes/1024938 to your computer and use it in GitHub Desktop.

Select an option

Save brenes/1024938 to your computer and use it in GitHub Desktop.
Color current git branch in prompt
# Color the current git branch in prompt
# red -> we are in master, take care!
# blue -> just a normal branch. Carry on
function __colorize_git_ps1 () {
local branch=$(__git_ps1 "%s")
if [ -n "$branch" ]; then
local color
if [[ $branch == master* ]]; then
color="31" #Red
fi
if [[ $branch == dev* ]]; then
color="32" #Green
fi
if [[ $branch == features* ]]; then
color="36" #Blue
fi
if [[ $branch == fix* ]]; then
color="35" #Light Red
fi
printf "[\e[${color}m${branch}\e[0m]"
fi
}
GIT_PS1_SHOWDIRTYSTATE=t
PS1='\w$(__colorize_git_ps1)\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment