Permalink
Browse files

Check if bin/ruby exists and is executable before switching Rubies.

  • Loading branch information...
postmodern committed Dec 29, 2012
1 parent f99bcd1 commit 372cbc9879230c9b64cebcd536d97077a46d0148
Showing with 7 additions and 3 deletions.
  1. +1 −2 ChangeLog.md
  2. +6 −1 share/chruby/chruby.sh
View
@@ -1,8 +1,7 @@
### 0.3.1 / 2012-12-28
* Fixed the auto-detection of `~/.rubies/*`.
-* Have `chruby_use` call `ruby` with an absolute path, for when JRuby
- does not symlink `bin/ruby` to `jruby`.
+* Check if `bin/ruby` exists and is executable before switching to a Ruby.
* Prevent `export=""` from accidently being set under [zsh].
* Prevent `script/setup.sh` from exiting if a `brew install` fails because all
packages are already installed.
View
@@ -22,13 +22,18 @@ function chruby_reset()
function chruby_use()
{
+ if [[ ! -x "$RUBY_ROOT/bin/ruby" ]]; then
+ echo "chruby: $RUBY_ROOT/bin/ruby not found" >&2
+ return 1
+ fi
+
[[ -n "$RUBY_ROOT" ]] && chruby_reset
export RUBY_ROOT="$1"
export RUBYOPT="$2"
export PATH="$RUBY_ROOT/bin:$PATH"
- eval `$RUBY_ROOT/bin/ruby - <<EOF
+ eval `ruby - <<EOF
require 'rubygems'
puts "export RUBY_ENGINE=#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'};"
puts "export RUBY_VERSION=#{RUBY_VERSION};"

0 comments on commit 372cbc9

Please sign in to comment.