Created
December 8, 2016 08:04
-
-
Save Anthchirp/dfc9a4382f8dfc9a97fe1039c9e6789a 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
#!/bin/bash | |
function parse_git_branch () { | |
if [[ -z $(git status --porcelain) ]]; then | |
echo -ne "\001\033[0;32m\002" | |
else | |
echo -ne "\001\033[1;31m\002" | |
fi | |
BRANCH=`git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
echo -n $BRANCH | |
REMOTE=`git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)` | |
if [ "$REMOTE" != "" ]; then | |
AHEAD=`git rev-list $REMOTE..HEAD | wc -l` # If you have git >=1.8: replace '| wc -l' by '--count' | |
BEHIND=`git rev-list HEAD..$REMOTE | wc -l` # same | |
if [ "$BEHIND" != "0" ]; then echo -ne "\001\033[1;31m\002-$BEHIND"; fi | |
if [ "$AHEAD" != "0" ]; then echo -ne "\001\033[1;32m\002+$AHEAD"; fi | |
fi | |
} | |
alias __ps1_gitstat='echo -en "\001\033[1;33m\002[`parse_git_branch`\001\033[1;33m\002] "' | |
PS1="\[\033[1;31m\]\h \[\033[1;34m\]\W \`if [ \$? = 0 ]; then echo '\[\033[1;32m\]:)'; else echo '\[\033[1;31m\]:('; fi\` \`git rev-parse 2>/dev/null && __ps1_gitstat\`\[\033[0m\]\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment