Created
July 24, 2011 02:02
-
-
Save elliotttf/1102105 to your computer and use it in GitHub Desktop.
git branch on terminal prompt
This file contains 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
# 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