Which RVM gemset am I on?
So jumping back and forth around the command line on different projects has made me constantly double check where I am at. Mostly because I’ve fallen a few times to the ‘oops, I installed that gem in the wrong gemset’ conundrum. Usually that is not a problem unless you’re working with some gems that have to build to the system. Anyway, I decided to solve this problem!
Inspired by this article, I’ve modified my command prompt so that the ruby version and gemset you are currently working on is displayed. I haven’t seen many people do this and was surprised to even find the article on how to set it up. So kudos to that guy.
I find it extremely useful and hopefully you will too. Just add this function into your bash profile:
function rvm_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local ruby_version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$ruby_version" != "" ] && ruby_version="$ruby_version"
local full="$ruby_version$gemset"
[ "$full" != "" ] && echo "$full "
}
And then activate it by adding to the PS1 variable. (I just added it to the front of mine. I’ve removed the rest of the mess that is my PS1 for simplicity)
export PS1='$(rvm_version) \w'
Boom… ruby version and gemset info straight to your face!
