Created
March 29, 2011 03:45
-
-
Save ChristopherMacGown/891777 to your computer and use it in GitHub Desktop.
git_rev_head
This file contains hidden or 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 git_rev_head | |
{ | |
rev_prompt_token=" » " | |
rev=1 | |
sym=0 | |
declare -a colors | |
declare -a branches | |
branches[$rev]=$(git name-rev --name-only head 2> /dev/null) | |
branches[$sym]=$(git symbolic-ref -q head 2> /dev/null) | |
branches[$sym]=${branches[$sym]##refs/heads/} | |
if [ ${#branches} -gt 0 ]; then | |
for branch in $sym $rev; do | |
case "${branches[$branch]}" in | |
production*|master*) colors[$branch]=${bold}${red_text} ;; | |
merge_*) colors[$branch]=${cyan_text} ;; | |
*) colors[$branch]=${green_text} | |
esac | |
done | |
sym_prompt="${colors[$sym]}${branches[$sym]}${reset}" | |
rev_prompt="${colors[$rev]}${branches[$rev]}${reset}${rev_prompt_token}" | |
if [ "${branches[$sym]}" = "${branches[$rev]}" ]; then rev_prompt=""; fi | |
echo "(${rev_prompt}${sym_prompt})" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment