Skip to content

Instantly share code, notes, and snippets.

@gorenje
Created February 3, 2011 09:44
Show Gist options
  • Save gorenje/809276 to your computer and use it in GitHub Desktop.
Save gorenje/809276 to your computer and use it in GitHub Desktop.
rvm & git in bash prompt
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