Created
March 7, 2012 13:21
-
-
Save kbrock/1993066 to your computer and use it in GitHub Desktop.
Colored Git prompts
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
# thanks from: http://aaroncrane.co.uk/2009/03/git_branch_prompt/ | |
function find_git_branch { | |
local dir=. head | |
git_dir=${PWD} | |
until [ "$dir" -ef / ]; do | |
if [ -f "$dir/.git/HEAD" ]; then | |
head=$(< "$dir/.git/HEAD") | |
if [[ $head == ref:\ refs/heads/* ]]; then | |
git_branch="${head#*/*/}" | |
elif [[ $head != '' ]]; then | |
git_branch='(detached)' | |
else | |
git_branch='(unknown)' | |
fi | |
git_root="${git_dir##*/}" | |
git_loc="${PWD/${git_dir}}" | |
#wish there was a way to do this not running all these commands | |
if ! $(git diff-files --ignore-submodules --quiet) ; then | |
#locally modified | |
git_status=32 | |
elif ! $(git diff-index --cached --quiet HEAD --) ; then | |
#committed, but not pushed | |
git_status=33 | |
else | |
git_status=36 | |
fi | |
return | |
fi | |
git_dir="${git_dir%/*}" | |
dir="../$dir" | |
done | |
# exported variables | |
git_status=36 | |
git_dir='' | |
git_branch='' | |
git_root='' | |
git_loc=${PWD##*/} | |
} | |
export PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND" | |
export PS1="[\[\033[\${git_status}m\]\${git_branch}\[\033[0m\]]\[\033[1;34m\] \${git_root}\[\033[0m\]\${git_loc} $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment