In Valid Logic

Endlessly expanding technology

You got RVM and git in my command prompt!

I had posted this to our internal wiki at work, but Scott had mentioned he was interested in it, so figured I’d throw it up here.

Zsh is the best shell. If you don’t know, now you know.

One thing that is a nice convenience is to setup the command prompt to include your current Ruby implementation, RVM gemset, and which branch of the git repository you are in. In our main codebase at Involver, my prompt looks like this:


From this, I can tell I’m using JRuby 1.5.1, the “involver” gemset. I’m in the “topsecret” project folder (I just have the current directory, not the full path), and the “git:master” indicates its a git repository and I’m in the master branch.

To achieve that, add the following into your .zshrc or one of the files you source into it.

 1 parse_git_branch() {
 2   git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\/git:\1/'
 3 }
 5 rvm_prompt() {
 6   $HOME/.rvm/bin/rvm-prompt v g
 7 }
 9 export PS1='%{$reset_color$fg[blue]%}$(rvm_prompt)%{$reset_color$fg[gray]%}:
10 %1~%{$reset_color$bold_color$fg[green]%}%{$reset_color$fg[green]%}
11 $(parse_git_branch)>%{$reset_color%} '

There are of course many more things you can do with zsh. I have this and other tidbits in my dotfiles repo on Github. And now that I think of it, have some stuff I haven’t checked in since I’m not in TextMate/Ruby/zsh all day.

Thursday, September 16, 2010

blog comments powered by Disqus