Created
February 17, 2012 07:41
-
-
Save dbrockman/1851609 to your computer and use it in GitHub Desktop.
Git aware bash PS1
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
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_git_status() { | |
local color="" | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
if git diff --quiet 2>/dev/null >&2 | |
then | |
color="${c_green}" | |
else | |
color=${c_red} | |
fi | |
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
local num=$(git status --porcelain 2> /dev/null | wc -l) | |
gitver="$color ($gitver, $num)$c_sgr0" | |
else | |
return 0 | |
fi | |
echo $gitver | |
} | |
PS1='\w$(parse_git_status): ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment