From dbeb6d4e1aefd22d688afc3140407a5c6ca5bbb9 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sat, 1 Feb 2014 23:37:29 -0500 Subject: [PATCH] [Fix #361] Load chruby when found --- modules/ruby/README.md | 23 +++++++++++++++++++---- modules/ruby/functions/ruby-info | 2 ++ modules/ruby/init.zsh | 7 +++++++ runcoms/zpreztorc | 7 +++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/modules/ruby/README.md b/modules/ruby/README.md index e78d757..152e26d 100644 --- a/modules/ruby/README.md +++ b/modules/ruby/README.md @@ -8,7 +8,7 @@ Local Gem Installation ---------------------- When a Ruby version manager is not detected, local gems are installed in -*~/Library/Ruby/Gems/1.8* on Mac OS X. +*~/.gems*; otherwise, they are installed according to the manager. RVM --- @@ -23,12 +23,27 @@ may conflict with shell scripts. rbenv ----- -An alternative RVM is to use [rbenv][3], which allows for switching between multiple, -isolated Ruby installations in the home directory. +An alternative RVM is to use [rbenv][3], which allows for switching between +multiple, isolated Ruby installations in the home directory. While it is not as feature rich as RVM, it is not loaded into the shell and is not known to cause conflicts with shell scripts. +chruby +------ + +Yet another alternative is [chruby][6], which is simpler than both RVM and +rbenv. + +### Settings + +#### Auto-Switch + +To enable auto switching the Ruby version on directory change based on the +.ruby-version file, add the following line to *zpreztorc*: + + zstyle ':prezto:module:ruby:chruby' auto-switch 'yes' + Bundler ------- @@ -87,4 +102,4 @@ Authors [3]: https://github.com/sstephenson/rbenv [4]: http://gembundler.com [5]: https://github.com/sorin-ionescu/prezto/issues - +[6]: https://github.com/postmodern/chruby diff --git a/modules/ruby/functions/ruby-info b/modules/ruby/functions/ruby-info index 7bc8ead..b3656dd 100644 --- a/modules/ruby/functions/ruby-info +++ b/modules/ruby/functions/ruby-info @@ -18,6 +18,8 @@ if (( $+commands[rvm-prompt] )); then version="$(rvm-prompt)" elif (( $+commands[rbenv] )); then version="$(rbenv version-name)" +elif (( $+commands[ruby] )); then + version="${${$(ruby --version)[(w)1,(w)2]}/ /-}" fi # Format version. diff --git a/modules/ruby/init.zsh b/modules/ruby/init.zsh index 89b1345..eb18dd3 100644 --- a/modules/ruby/init.zsh +++ b/modules/ruby/init.zsh @@ -23,6 +23,13 @@ elif [[ -s "$HOME/.rbenv/bin/rbenv" ]]; then elif (( $+commands[rbenv] )); then eval "$(rbenv init - --no-rehash zsh)" +# Load package manager installed chruby into the shell session. +elif (( $+commands[chruby-exec] )); then + source "${commands[chruby-exec]:h:h}/share/chruby/chruby.sh" + if zstyle -t ':prezto:module:ruby:chruby' auto-switch; then + source "${commands[chruby-exec]:h:h}/share/chruby/auto.sh" + fi + # Prepend local gems bin directories to PATH. else path=($HOME/.gem/ruby/*/bin(N) $path) diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 9dd6c5d..80f2a05 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -87,6 +87,13 @@ zstyle ':prezto:module:editor' key-bindings 'emacs' # Auto set to 'off' on dumb terminals. zstyle ':prezto:module:prompt' theme 'sorin' +# +# Ruby +# + +# Auto switch the Ruby version on directory change. +# zstyle ':prezto:module:ruby:chruby' auto-switch 'yes' + # # Screen #