I wanted to migrate some of my previous code snippets from my tumblr blog http://tumblr.com/benwoodall to here, and I also wanted to test out some of the available plugins. So here post number 1!
c_cyan=`tput setaf 6`c_red=`tput setaf 1`c_green=`tput setaf 2`c_sgr0=`tput sgr0`parse_git_branch (){if git rev-parse --git-dir >/dev/null 2>&1
thengit_status="$(git status 2> /dev/null)"branch_pattern="^# On branch ([^${IFS}]*)"remote_pattern="# Your branch is (.*) of"diverge_pattern="# Your branch and (.*) have diverged"merge_pattern="# unmerged:"# add an else if or two here if you want to get more specificif[[${git_status}=~ ${remote_pattern}]]; then if[[${BASH_REMATCH[1]}=="ahead"]]; thenremote="↑"elif[${BASH_REMATCH[1]}=="behind"]]; thenremote="↓"fi fi if[[${git_status}=~ ${diverge_pattern}]]; thenremote="↕"fi if[[${git_status}=~ ${merge_pattern}]]; thenremote="|MERGING"fi if[[${git_status}=~ ${branch_pattern}]]; thenbranch=${BASH_REMATCH[1]}echo"${branch}${remote}"fi else return 0
fi}branch_color (){if git rev-parse --git-dir >/dev/null 2>&1
thengit_status="$(git status 2> /dev/null)"color=""if[[${git_status}=~ "working directory clean"]]; thencolor="${c_green}"elsecolor=${c_red}fi else return 0
fiecho -ne $color}export PS1='\h:\W$(__git_ps1 "[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]]\[\e[0m\]")$ '