Skip to content

Instantly share code, notes, and snippets.

@spalger
Created August 23, 2013 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spalger/6322190 to your computer and use it in GitHub Desktop.
Save spalger/6322190 to your computer and use it in GitHub Desktop.
get the branch name in the PS1
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
else
return 0
fi
echo -e ":$(branch_color)$gitver${c_plain}"
}
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
color="${c_clean}"
else
color=${c_dirty}
fi
else
return 0
fi
echo -ne $color
}
PS1='\[${c_wdir}\]\W\[${c_plain}\]$(parse_git_branch) $ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment