Skip to content

Instantly share code, notes, and snippets.

@afgomez
Created April 7, 2011 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save afgomez/908717 to your computer and use it in GitHub Desktop.
Save afgomez/908717 to your computer and use it in GitHub Desktop.
Color current git branch in prompt
# Color the current git branch in prompt
# red -> master branch, take care!
# blue -> just a normal branch
# green -> dev branch
# cyan -> feature branch
# magenta -> fix branch
function __colorize_git_ps1 () {
local branch=$(__git_ps1 "%s")
if [ -n "$branch" ]; then
local color="34" # blue
if [[ $branch == master* ]]; then
color="31" # Red
fi
if [[ $branch == dev* ]]; then
color="32" # Green
fi
if [[ $branch == features* ]]; then
color="36" # Cyan
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