summaryrefslogtreecommitdiff
path: root/plugins/chruby
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/chruby')
-rw-r--r--plugins/chruby/README.md20
-rw-r--r--plugins/chruby/chruby.plugin.zsh38
2 files changed, 50 insertions, 8 deletions
diff --git a/plugins/chruby/README.md b/plugins/chruby/README.md
new file mode 100644
index 000000000..d373006a5
--- /dev/null
+++ b/plugins/chruby/README.md
@@ -0,0 +1,20 @@
+# chruby plugin
+
+This plugin loads [chruby](https://github.com/postmodern/chruby), a tool that changes the
+current Ruby version, and completion and a prompt function to display the Ruby version.
+Supports brew and manual installation of chruby.
+
+To use it, add `chruby` to the plugins array in your zshrc file:
+```zsh
+plugins=(... chruby)
+```
+
+## Usage
+
+If you'd prefer to specify an explicit path to load chruby from
+you can set variables like so:
+
+```
+zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
+zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
+```
diff --git a/plugins/chruby/chruby.plugin.zsh b/plugins/chruby/chruby.plugin.zsh
index b461b0c9b..f7fedb5f2 100644
--- a/plugins/chruby/chruby.plugin.zsh
+++ b/plugins/chruby/chruby.plugin.zsh
@@ -16,15 +16,28 @@
# rvm and rbenv plugins also provide this alias
alias rubies='chruby'
-local _chruby_path
-local _chruby_auto
_homebrew-installed() {
whence brew &> /dev/null
+ _xit=$?
+ if [ $_xit -eq 0 ];then
+ # ok , we have brew installed
+ # speculatively we check default brew prefix
+ if [ -h /usr/local/opt/chruby ];then
+ _brew_prefix="/usr/local/opt/chruby"
+ else
+ # ok , it is not default prefix
+ # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
+ _brew_prefix=$(brew --prefix chruby)
+ fi
+ return 0
+ else
+ return $_xit
+ fi
}
_chruby-from-homebrew-installed() {
- [ -r $(brew --prefix chruby)] &> /dev/null
+ [ -r _brew_prefix ] &> /dev/null
}
_ruby-build_installed() {
@@ -42,14 +55,17 @@ if _ruby-build_installed; then
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 ${_chruby_path} && [[ -r ${_chruby_path} ]]; then
+ if [[ -r ${_chruby_path} ]]; then
source ${_chruby_path}
fi
- if ${_chruby_auto} && [[ -r ${_chruby_auto} ]]; then
+ if [[ -r ${_chruby_auto} ]]; then
source ${_chruby_auto}
fi
}
@@ -64,8 +80,8 @@ _chruby_dirs() {
}
if _homebrew-installed && _chruby-from-homebrew-installed ; then
- source $(brew --prefix chruby)/share/chruby/chruby.sh
- source $(brew --prefix chruby)/share/chruby/auto.sh
+ source $_brew_prefix/share/chruby/chruby.sh
+ source $_brew_prefix/share/chruby/auto.sh
_chruby_dirs
elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
source /usr/local/share/chruby/chruby.sh
@@ -95,5 +111,11 @@ function chruby_prompt_info() {
}
# complete on installed rubies
-_chruby() { compadd $(chruby | tr -d '* ') }
+_chruby() {
+ compadd $(chruby | tr -d '* ')
+ local default_path='/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
+ if PATH=${default_path} type ruby &> /dev/null; then
+ compadd system
+ fi
+}
compdef _chruby chruby