Created
April 7, 2011 21:06
-
-
Save afgomez/908717 to your computer and use it in GitHub Desktop.
Color current git branch in prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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