Skip to content

Instantly share code, notes, and snippets.

@elliotttf
Created July 24, 2011 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotttf/1102105 to your computer and use it in GitHub Desktop.
Save elliotttf/1102105 to your computer and use it in GitHub Desktop.
git branch on terminal prompt
# Add current git branch (if applicale) to the terminal prompt.
function pgb {
ref=$(/usr/bin/git symbolic-ref HEAD 2> /dev/null) || return
dirty=""
untracked=""
# Disallow unstaged changes in the working tree
if ! /usr/bin/git diff-files --quiet --ignore-submodules --
then
dirty="*"
fi
# Disallow uncommitted changes in the index
if ! /usr/bin/git diff-index --cached --quiet HEAD --ignore-submodules --
then
dirty="*"
fi
status=`/usr/bin/git status --porcelain 2>/dev/null| grep "^??" | wc -l`
if [ $status -gt 0 ]; then
untracked="+"
fi
echo " ("${ref#refs/heads/}"$dirty$untracked)"
}
PS1="${PS1/\\$/\$(pgb)\\$}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment