5c14474eb2a252ad61e55cf084c5bbe6c1c934b9

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

style(chruby): fix plugin code style and loading process

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/chruby/README.md b/plugins/chruby/README.md
  2index d373006a526c8449f6261d0713cecb90f5f3e2be..19eb15a8df551c8a61a8bf08f35fcfc194cd009f 100644
  3--- a/plugins/chruby/README.md
  4+++ b/plugins/chruby/README.md
  5@@ -5,6 +5,7 @@ current Ruby version, and completion and a prompt function to display the Ruby v
  6 Supports brew and manual installation of chruby.
  7 
  8 To use it, add `chruby` to the plugins array in your zshrc file:
  9+
 10 ```zsh
 11 plugins=(... chruby)
 12 ```
 13@@ -14,7 +15,7 @@ plugins=(... chruby)
 14 If you'd prefer to specify an explicit path to load chruby from
 15 you can set variables like so:
 16 
 17-```
 18+```zsh
 19 zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
 20 zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
 21 ```
 22diff --git a/plugins/chruby/chruby.plugin.zsh b/plugins/chruby/chruby.plugin.zsh
 23index 32f0525aa9d3a8cb4c51afaf7ed938f894a4e8ee..61ded3b73e135c9ce3c48a601b3bd0f6e5ccc70a 100644
 24--- a/plugins/chruby/chruby.plugin.zsh
 25+++ b/plugins/chruby/chruby.plugin.zsh
 26@@ -1,121 +1,94 @@
 27-#
 28-# INSTRUCTIONS
 29-#
 30-#  With either a manual or brew installed chruby things should just work.
 31-#
 32-#  If you'd prefer to specify an explicit path to load chruby from
 33-#  you can set variables like so:
 34-#
 35-#    zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
 36-#    zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
 37-# 
 38-# TODO
 39-#  - autodetermine correct source path on non OS X systems
 40-#  - completion if ruby-install exists
 41+## load chruby from different locations
 42 
 43-# rvm and rbenv plugins also provide this alias
 44-alias rubies='chruby'
 45+_source-from-omz-settings() {
 46+  local _chruby_path _chruby_auto
 47+  
 48+  zstyle -s :omz:plugins:chruby path _chruby_path || return 1
 49+  zstyle -s :omz:plugins:chruby auto _chruby_auto || return 1
 50 
 51+  if [[ -r ${_chruby_path} ]]; then
 52+    source ${_chruby_path}
 53+  fi
 54 
 55-_homebrew-installed() {
 56-    whence brew &> /dev/null
 57-    _xit=$?
 58-    if [ $_xit -eq 0 ];then
 59-    	# ok , we have brew installed
 60-	# speculatively we check default brew prefix
 61-        if [ -h  /usr/local/opt/chruby ];then
 62-		_brew_prefix="/usr/local/opt/chruby"
 63-	else
 64-		# ok , it is not default prefix 
 65-		# this call to brew is expensive ( about 400 ms ), so at least let's make it only once
 66-		_brew_prefix=$(brew --prefix chruby)
 67-	fi
 68-	return 0
 69-   else
 70-        return $_xit
 71-   fi
 72+  if [[ -r ${_chruby_auto} ]]; then
 73+    source ${_chruby_auto}
 74+  fi
 75 }
 76 
 77-_chruby-from-homebrew-installed() {
 78-  [ -r $_brew_prefix ] &> /dev/null
 79-}
 80+_source-from-homebrew() {
 81+  (( $+commands[brew] )) || return 1
 82 
 83-_ruby-build_installed() {
 84-    whence ruby-build &> /dev/null
 85-}
 86+  local _brew_prefix
 87+  # check default brew prefix
 88+  if [[ -h /usr/local/opt/chruby ]];then
 89+    _brew_prefix="/usr/local/opt/chruby"
 90+  else
 91+    # ok , it is not default prefix 
 92+    # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
 93+    _brew_prefix=$(brew --prefix chruby)
 94+  fi
 95 
 96-_ruby-install-installed() {
 97-    whence ruby-install &> /dev/null
 98-}
 99+  [[ -r "$_brew_prefix" ]] || return 1
100 
101-# Simple definition completer for ruby-build
102-if _ruby-build_installed; then
103-    _ruby-build() { compadd $(ruby-build --definitions) }
104-    compdef _ruby-build ruby-build
105-fi
106-
107-_source_from_omz_settings() {
108-    local _chruby_path
109-    local _chruby_auto
110-    
111-    zstyle -s :omz:plugins:chruby path _chruby_path
112-    zstyle -s :omz:plugins:chruby auto _chruby_auto
113-
114-    if [[ -r ${_chruby_path} ]]; then
115-        source ${_chruby_path}
116-    fi
117-
118-    if [[ -r ${_chruby_auto} ]]; then
119-        source ${_chruby_auto}
120-    fi
121+  source $_brew_prefix/share/chruby/chruby.sh
122+  source $_brew_prefix/share/chruby/auto.sh
123 }
124 
125-_chruby_dirs() {