Created
October 16, 2013 12:07
-
-
Save eduresende/7006685 to your computer and use it in GitHub Desktop.
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
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