Created
February 3, 2011 09:44
-
-
Save gorenje/809276 to your computer and use it in GitHub Desktop.
rvm & git in bash prompt
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 rvm_version { | |
if [ -x ~/.rvm/bin/rvm-prompt ] ; then | |
echo $(~/.rvm/bin/rvm-prompt) | |
else | |
echo " - no rvm - " | |
fi | |
} | |
function parse_git_branch { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
local a="" | |
lb=${ref#refs/heads/} | |
local ro=$(git config --get branch.${lb}.remote || echo "origin") | |
local rb=$(git config --get branch.${lb}.merge) | |
rb=${rb#refs/heads/} | |
local ab= | |
if [ "" != "${rb}" ]; then | |
ab="(+$(git log --pretty=format:%H ${ro}/${rb}..${lb} | wc -w | sed s'/ //'g))" | |
if [ "(+0)" = "${ab}" ]; then | |
ab="(-$(git log --pretty=format:%H ${lb}..${ro}/${rb} | wc -w | sed s'/ //'g))" | |
fi | |
if [ "(-0)" = "${ab}" ]; then | |
ab="" | |
fi | |
fi | |
echo "("${ref#refs/heads/}")${ab}" | |
} | |
PS1='++[\u\[\033[01;37m\]$(parse_git_branch),\[\033[01;33m\]$(rvm_version)\[\033[00m\]]'$HOST':\w @ \d \t\n+\!+> ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment