Using rbenv with tmuxinator

Tmuxinator allows for easy configuration of tmux sessions. Its a handy gem, but hasn’t received any major updates in quite some time. While it has support for specifying a project-level rvm version, it has not yet accepted either pull request that would add proper rbenv support. Not wanting to install a fork from GitHub, I found I could easily use the existing rvm support if I just shimmed calls to rvm into the equivalent call in rbenv.

Tmuxinator will call rvm use and pass the version identifier set in the rvm key of the configuration file. All I had to do was translate this into the equivalent call to rbenv shell. I added the following function to my zsh configuration:

function rvm () {
  if [[ $1 == 'use' ]]; then
    rbenv shell $2
  fi
}

I’m a total shell hack and recognize that this isn’t very robust, but it gets this sepecific job done. If all you need is for the tmuxinator-initiated tmux session to respect the rbenv local setting for the initial directory, then Ian Yang’s solution may work great for you. In my case, I wanted all initialized windows to use the same version of ruby, regardless of whether they had a local ruby version set. As an added bonus, expanding this function to translate other calls may help other rvm-supporting tools support rbenv.