Created
March 5, 2010 19:00
-
-
Save ryross/323014 to your computer and use it in GitHub Desktop.
bash script for git branch recognition
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
function find_git_branch { | |
local dir=. head | |
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 | |
return | |
fi | |
dir="../$dir" | |
done | |
git_branch='' | |
} | |
green=$'\e[1;32m' | |
magenta=$'\e[1;35m' | |
normal_colours=$'\e[m' | |
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND" | |
PS1="\[$green\]\u@\h:\W\[$magenta\]\$git_branch\[$green\]\\$\[$normal_colours\] " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment