Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created November 18, 2011 14:34
Show Gist options
  • Select an option

  • Save shreyansb/1376607 to your computer and use it in GitHub Desktop.

Select an option

Save shreyansb/1376607 to your computer and use it in GitHub Desktop.
improved git branch status in your bash prompt
txtred='\033[1;31m'
txtgrn='\033[1;32m'
txtylw='\033[1;33m'
end='\033[0m'
function parse_git {
branch="$(__git_ps1 "%s")"
if [[ -z $branch ]]; then
return
fi
status="$(git status 2>/dev/null)"
if [[ $status =~ "Untracked files" ]]; then
branch="${txtred}(${branch})${end}"
elif [[ $status =~ "Changes not staged for commit" ]]; then
branch="${txtred}(${branch})${end}"
elif [[ $status =~ "Changes to be committed" ]]; then
branch="${txtylw}(${branch})${end}"
elif [[ $status =~ "Your branch is ahead" ]]; then
branch="${txtylw}(${branch})${end}"
elif [[ $status =~ "nothing to commit" ]]; then
branch="${txtgrn}(${branch})${end}"
fi
echo -e $branch
}
PS1='[\u@$HOSTNAME \[\e[2;32m\]\w\[\e[m\] $(parse_git)]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment