mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-10-14 15:49:09 +00:00
ruby: Cleanup and optimize 'ruby' module
Changes: - Honor `$RBENV_ROOT` or `RVM_DIR` if set but, no need to set it explicitly if not set. Instead, let the respective initialization scripts take care of that. - Reverse `rbenv` vs `rvm` selection order, preferring `rbenv` instead. - Check for availability of `rbenv` or `rvm` function instead of command to validate requirements. In a properly configured and initialized shell, `rbenv` or `rvm` will be available as function. - Adhere to more idiomatic Zsh operation and minimize redundant syntaxes. For additional rationale, see: https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F
This commit is contained in:
committed by
Indrajit Raychaudhuri
parent
afe59b293b
commit
37443368c1
@@ -1,27 +1,32 @@
|
||||
#
|
||||
# Configures Ruby local gem installation, loads version managers, and defines
|
||||
# Configures Ruby local installation, loads version managers, and defines
|
||||
# aliases.
|
||||
#
|
||||
# Authors: Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
# Indrajit Raychaudhuri <irc@indrajit.com>
|
||||
#
|
||||
|
||||
# Load RVM into the shell session.
|
||||
if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
|
||||
# Possible lookup locations for manually installed rbenv and rvm.
|
||||
local_rbenv_paths=({$RBENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}rbenv}/bin/rbenv(N))
|
||||
local_rvm_paths=({$RVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}rvm}/scripts/rvm(N))
|
||||
|
||||
# Load manually installed or package manager installed rbenv into the shell
|
||||
# session.
|
||||
if (( $#local_rbenv_paths || $+commands[rbenv] )); then
|
||||
|
||||
# Ensure manually installed rbenv is added to path when present.
|
||||
[[ -s $local_rbenv_paths[1] ]] && path=($local_rbenv_paths[1]:h $path)
|
||||
|
||||
eval "$(rbenv init - zsh)"
|
||||
|
||||
# Load manually installed rvm into the shell session.
|
||||
elif (( $#local_rvm_paths )); then
|
||||
# Unset AUTO_NAME_DIRS since auto adding variable-stored paths to ~ list
|
||||
# conflicts with RVM.
|
||||
# conflicts with rvm.
|
||||
unsetopt AUTO_NAME_DIRS
|
||||
|
||||
# Source RVM.
|
||||
source "$HOME/.rvm/scripts/rvm"
|
||||
|
||||
# Load manually installed rbenv into the shell session.
|
||||
elif [[ -s "${RBENV_ROOT:=$HOME/.rbenv}/bin/rbenv" ]]; then
|
||||
path=("${RBENV_ROOT}/bin" $path)
|
||||
eval "$(rbenv init - --no-rehash zsh)"
|
||||
|
||||
# Load package manager installed rbenv into the shell session.
|
||||
elif (( $+commands[rbenv] )); then
|
||||
eval "$(rbenv init - --no-rehash zsh)"
|
||||
source "$local_rvm_paths[1]"
|
||||
|
||||
# Load package manager installed chruby into the shell session.
|
||||
elif (( $+commands[chruby-exec] )); then
|
||||
@@ -34,7 +39,7 @@ elif (( $+commands[chruby-exec] )); then
|
||||
source "${commands[chruby-exec]:h:h}/share/chruby/auto.sh"
|
||||
fi
|
||||
|
||||
# If a default Ruby is set, switch to it.
|
||||
# If a default ruby is set, switch to it.
|
||||
chruby_auto
|
||||
fi
|
||||
|
||||
@@ -43,8 +48,10 @@ else
|
||||
path=($HOME/.gem/ruby/*/bin(N) $path)
|
||||
fi
|
||||
|
||||
unset local_rbenv
|
||||
|
||||
# Return if requirements are not found.
|
||||
if (( ! $+commands[ruby] && ! ( $+commands[rvm] || $+commands[rbenv] ) )); then
|
||||
if (( ! $+commands[ruby] && ! $#functions[(i)r(benv|vm)] )); then
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user