Skip to content

Instantly share code, notes, and snippets.

@eduresende
Created October 16, 2013 12:07
Show Gist options
  • Save eduresende/7006685 to your computer and use it in GitHub Desktop.
Save eduresende/7006685 to your computer and use it in GitHub Desktop.
parse_git_branch ()
{
local GITDIR=`git rev-parse --show-toplevel 2>&1` # Get root directory of git repo
if [[ "$GITDIR" != '/Users/eduardo' ]] # Don't show status of home directory repo
then
# Figure out the current branch, wrap in brackets and return it
local BRANCH=`git branch 2>/dev/null | sed -n '/^\*/s/^\* //p'`
if [ -n "$BRANCH" ]; then
echo -e "[$BRANCH]"
fi
else
echo ""
fi
}
function git_color () {
# Get the status of the repo and chose a color accordingly
local STATUS=`git status 2>&1`
if [[ "$STATUS" == *'Not a git repository'* ]]
then
echo ""
else
if [[ "$STATUS" != *'working directory clean'* ]]
then
# red if need to commit
echo -e '\033[0;33m'
else
if [[ "$STATUS" == *'Your branch is ahead'* ]]
then
# yellow if need to push
echo -e '\033[0;33m'
else
# else cyan
echo -e '\033[0;36m'
fi
fi
fi
}
PS1='\n\n\n\033[01;34m\]\w\[\033[00m\] \[$(git_color)\]$(parse_git_branch) \[\033[01;32m\]\[\033[00m\]\[\n $ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment