wayneeseguin/rvm — pull request #3223 by dholdren (2014-12-24 01:02:59+00:00)
Title: allow use of errexit (-e) when scripting rvm

The cd hook is broken when scripting rvm with `set -e` (errexit),
in the particular case where a Gemfile is present and does *not* contain a ruby version directive

### Steps to reproduce
Running this script:
```
#!/bin/bash
set -e

source "$HOME/.rvm/scripts/rvm" #so 'cd' will change gemset when dotfiles present

#setup
rm -rf ~/tmp/dir_with_gemfile
mkdir -p ~/tmp/dir_with_gemfile

# a Gemfile with no ruby version information
echo "source 'https://rubygems.org'" > ~/tmp/dir_with_gemfile/Gemfile
echo "gem 'rails'" >> ~/tmp/dir_with_gemfile/Gemfile
#end setup

#works
echo 'pre cd ~'
cd ~
echo 'post cd ~'

#exits after "cd"
echo 'pre cd ~/tmp/dir_with_gemfile'
cd ~/tmp/dir_with_gemfile
echo 'post cd ~/tmp/dir_with_gemfile'
```
The output is: (notice it does not get to the last line)
```
pre cd ~
post cd ~
pre cd ~/tmp/dir_with_gemfile
```

running with `set -x` I get the following as the last few lines of output:
```
+ [[ -s /Users/dholdren/tmp/dir_with_gemfile/Gemfile ]]
+ __rvm_grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
+ GREP_OPTIONS=
+ command grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
+ grep '^#ruby=' /Users/dholdren/tmp/dir_with_gemfile/Gemfile
```

### Solution
bash won't cause an exit while using `errexit` if the command is within an `if` expression, so I moved the greps for a ruby directive in the Gemfile into an `if`