Pimp out your rvm profile

We’ve been using RVM for all our Rails projects here at Blenderbox for some time and we’ve made it a whole lot easier to use by adding this .rvmrc file to the root directory of all our projects.

#!/usr/bin/env bash


if rvm list strings | grep -q "${ruby_string}" ; then

  # Load or create the specified environment
  if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
    && -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
    \. "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}"
    rvm --create  "${ruby_string}@${gemset_name}"


  # Notify the user to install the desired interpreter before proceeding.
  echo "${ruby_string} was not found, please run 'rvm install ${ruby_string}' and then cd back into the project directory."

# Ensure that Bundler is installed, install it if it is not.
if ! command -v bundle ; then
	printf "The rubygem 'bundler' is not installed, installing it now.\n"
	gem install bundler

What this little beauty does is looks for a ruby version and gemset that you set in the script and switches to it.  If it doesn’t exist but you have the ruby version installed, it will create a gemset for you and automatically switch to it.  If you don’t have that ruby version installed, it prompts you to install it before it creates the gemset.

It’s pretty awesome, so I hope you give it a try.  Once you do, you’ll never know how you lived with out it!  I’ve even used it for a few django projects to automatically switch to the right virtualenv and start up tmux.

Posted in | Comments Off on Pimp out your rvm profile

Comments are closed.