postmodern/chruby — pull request #141 by DavidEGrayson (2013-05-21 19:01:26+00:00)
Title: Fix chruby to not remove /bin from the path

Hello. Thanks for making this beautifully simple Ruby version switcher. When something goes wrong, I can easily see why. In this case, a few times I found myself in a situation where `/bin` had been removed from my PATH, crippling my shell. I found the lines in `chruby.sh` that were responsible for this happening:

export PATH=${PATH//:$GEM_HOME\/bin:/:}
export PATH=${PATH//:$GEM_ROOT\/bin:/:}

If either `GEM_HOME` or `GEM_ROOT` happens to be unset or empty, the result of those lines is to remove `/bin` from the PATH. The solution I present in this pull request is to change those two lines, adding a test to make sure the variables are not empty:

[[ -n "$GEM_HOME" ]] && export PATH=${PATH//:$GEM_HOME\/bin:/:}
[[ -n "$GEM_ROOT" ]] && export PATH=${PATH//:$GEM_ROOT\/bin:/:}

You might be wondering why `GEM_HOME` or `GEM_ROOT` were empty. In chruby 0.3.4, if rubygems is not installed then the little ruby script inside chruby_use would throw an exception and fail to set `GEM_ROOT`. I see that in the latest version of chruby from github, you have fixed the ruby script to gracefully handle that situation, but it still does not set `GEM_ROOT`.