Merge pull request #1 from tilgovi/chruby-performance

Avoid brew unless necessary to find chruby
This commit is contained in:
Michal Cichra 2017-08-12 09:46:08 +02:00 committed by GitHub
commit 26d0d550ba

View file

@ -8,7 +8,7 @@
# #
# zstyle :omz:plugins:chruby path /local/path/to/chruby.sh # zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
# zstyle :omz:plugins:chruby auto /local/path/to/auto.sh # zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
# #
# TODO # TODO
# - autodetermine correct source path on non OS X systems # - autodetermine correct source path on non OS X systems
# - completion if ruby-install exists # - completion if ruby-install exists
@ -36,33 +36,34 @@ if _ruby-build_installed; then
compdef _ruby-build ruby-build compdef _ruby-build ruby-build
fi fi
_source_from_omz_settings() {
local _chruby_path
local _chruby_auto
zstyle -s :omz:plugins:chruby path _chruby_path
zstyle -s :omz:plugins:chruby auto _chruby_auto
if [[ -r "$_chruby_path" ]]; then
source "$_chruby_path"
fi
if [[ -r "$_chruby_auto" ]]; then
source "$_chruby_auto"
fi
}
function () { function () {
local _chruby_homebrew_prefix="$(brew --prefix chruby 2> /dev/null)" local _path
local _auto
local _prefix="/usr/local/share/chruby"
if _homebrew-installed && [[ -r "$_chruby_homebrew_prefix" ]] ; then # Honor explicit user preference
source "${_chruby_homebrew_prefix}/share/chruby/chruby.sh" zstyle -s :omz:plugins:chruby path _path
source "${_chruby_homebrew_prefix}/share/chruby/auto.sh" zstyle -s :omz:plugins:chruby auto _auto
elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
source /usr/local/share/chruby/chruby.sh # Default to /usr/local/share/chruby if either is not defined
source /usr/local/share/chruby/auto.sh [[ -r "$_path" ]] || _path="${_prefix}/chruby.sh"
else [[ -r "$_auto" ]] || _auto="${_prefix}/auto.sh"
_source_from_omz_settings
# Fall back on homebrew
if [[ ! ( -r "$_path" && -r "$_auto" ) ]]; then
if _homebrew-installed; then
_prefix="$(brew --prefix chruby 2> /dev/null)/share/chruby"
[[ -r "$_path" ]] || _path="${_prefix}/chruby.sh"
[[ -r "$_auto" ]] || _auto="${_prefix}/auto.sh"
fi
fi
if [[ -r "$_path" ]]; then
source "$_path"
fi
if [[ -r "$_auto" ]]; then
source "$_auto"
fi fi
} }