If you’re like me, most of your day is working in Git and RVM. I am frequently typing git branch to remember what branch I’m on, and rvm gemdir to remember what ruby version and gemset I’m using. With all those wasted cycles, there has to be a better way. And there is.

RVM comes with a built in shell prompt, and with a little magic you can combine that with git information. Add the following to your ~/.bashrc :

export PS1="\[\033[01;34m\]\$(~/.rvm/bin/rvm-prompt) \[\033[01;32m\]\w\[\033[00;33m\]\$(__git_ps1 \" (%s)\") \[\033[01;36m\]\$\[\033[00m\] "

Then in the terminal as my daily workflow moves me between git branches and rvm versions (whether explicitly or by .rvmrc), the prompt will always keep me up to date with my context. (The command line uses colors that aren’t shown in the snippet below).

ruby-1.9.2-p180 ~ $ cd projects/harvested/code/ ruby-1.9.2-p180 ~/projects/harvested/code (master) $ git checkout test-branch Switched to branch 'test-branch' ruby-1.9.2-p180 ~/projects/harvested/code (test-branch) $ rvm use 1.8.7 Using /Users/zmoazeni/.rvm/gems/ruby-1.8.7-p334 ruby-1.8.7-p334 ~/projects/harvested/code (test-branch) $ rvm use [email protected] --create Using /Users/zmoazeni/.rvm/gems/ruby-1.8.7-p334 with gemset mygemset [email protected] ~/projects/harvested/code (test-branch) $

Try it out and see if you like it. It’s been a big sigh of relief for me. Kudos to Chris Gaffney for the inspiration and for figuring out the git portion.

If you have trouble with the Git and/or RVM portions, make sure you have bash-completion installed. Git should install by default with homebrew, but you will need to put something similar in your ~/.bashrc before the PS1 declaration: