Chruby and the .git/safe PATH hack

Hi,

A common hack Thoughtbot use is to add project binstubs to the PATH. For example, if we’ve got rspec in our bin directory, we can just run rspec instead of bin/rspec or bundle exec rspec.

It worked when I used rbenv, but since moving to chruby, it doesn’t work anymore. No matter what I do, the path to my ruby is appears first in my $PATH.

Here’s an excerpt from my zshenv:

if [[ -e /usr/local/share/chruby ]]; then
  source '/usr/local/share/chruby/chruby.sh'
  source '/usr/local/share/chruby/auto.sh'
  if [[ -f ~/.ruby-version ]]; then
    chruby $(cat ~/.ruby-version)
  fi
fi

export PATH="$HOME/.bin:$PATH"

# mkdir -p .git/safe in the root of repositories you trust
export PATH=".git/safe/../../bin:$PATH"

@christoomey I know you’re a chruby user, do you have any tips for me? Thanks!

I’ve got one project that uses direnv, so I was able to add PATH_add bin to its .envrc to get the desired behaviour.

I’d rather not have to add (and git ignore) .envrc files everywhere though.

Reference: Steve Tooke - Using `direnv` and `chruby` together

I’ve not run into this myself as I use bundle exec, but I think this blog post has a solution.

Thanks a lot! :slight_smile:

@christoomey How do you set up your PATH so that vim plugins like spec runners find the right gem if you only use bundle exec? I’ve found some plugins don’t easily allow me to override the command it runs, i.e. they expect to be able to run command like rspec on their own and just work.

I actually do very little with Vim integrating to external commands, and instead use tmux functionality to interact with the commands. I’m a fan of the Vim / Unix approach of singular focus for a given tool, so I keep Vim focused on editing, with tmux allowing me to interact with those commands as needed from Vim.

You can see the specific testing workflow I use in the Vim Integration video on the tmux trail. The same holds for most other commands, even recently moving away from my Git workflow in Vim via pathogen, to using gitsh in a tmux pane.