66a33b80c3c5c768bab0fd4bbed37851fcc01675

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #2261 from webframp/feature/chruby-plugin

Add simple plugin for chruby ruby version manager

Diff

  1diff --git a/plugins/chruby/chruby.plugin.zsh b/plugins/chruby/chruby.plugin.zsh
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..2a2c80cf67e637fada84a931134debb3e5f1df15
  4--- /dev/null
  5+++ b/plugins/chruby/chruby.plugin.zsh
  6@@ -0,0 +1,99 @@
  7+#
  8+# INSTRUCTIONS
  9+#
 10+#  With either a manual or brew installed chruby things should just work.
 11+#
 12+#  If you'd prefer to specify an explicit path to load chruby from
 13+#  you can set variables like so:
 14+#
 15+#    zstyle :omz:plugins:chruby path /local/path/to/chruby.sh
 16+#    zstyle :omz:plugins:chruby auto /local/path/to/auto.sh
 17+# 
 18+# TODO
 19+#  - autodetermine correct source path on non OS X systems
 20+#  - completion if ruby-install exists
 21+
 22+# rvm and rbenv plugins also provide this alias
 23+alias rubies='chruby'
 24+
 25+local _chruby_path
 26+local _chruby_auto
 27+
 28+_homebrew-installed() {
 29+    whence brew &> /dev/null
 30+}
 31+
 32+_chruby-from-homebrew-installed() {
 33+    brew --prefix chruby &> /dev/null
 34+}
 35+
 36+_ruby-build_installed() {
 37+    whence ruby-build &> /dev/null
 38+}
 39+
 40+_ruby-install-installed() {
 41+    whence ruby-install &> /dev/null
 42+}
 43+
 44+# Simple definition completer for ruby-build
 45+if _ruby-build_installed; then
 46+    _ruby-build() { compadd $(ruby-build --definitions) }
 47+    compdef _ruby-build ruby-build
 48+fi
 49+
 50+_source_from_omz_settings() {
 51+    zstyle -s :omz:plugins:chruby path _chruby_path
 52+    zstyle -s :omz:plugins:chruby auto _chruby_auto
 53+
 54+    if _chruby_path && [[ -r _chruby_path ]]; then
 55+        source ${_chruby_path}
 56+    fi
 57+
 58+    if _chruby_auto && [[ -r _chruby_auto ]]; then
 59+        source ${_chruby_auto}
 60+    fi
 61+}
 62+
 63+_chruby_dirs() {
 64+    chrubydirs=($HOME/.rubies/ $PREFIX/opt/rubies)
 65+    for dir in chrubydirs; do
 66+        if [[ -d $dir ]]; then
 67+            RUBIES+=$dir
 68+        fi
 69+    done
 70+}
 71+
 72+if _homebrew-installed && _chruby-from-homebrew-installed ; then
 73+    source $(brew --prefix chruby)/share/chruby/chruby.sh
 74+    source $(brew --prefix chruby)/share/chruby/auto.sh
 75+    _chruby_dirs
 76+elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
 77+    source /usr/local/share/chruby/chruby.sh
 78+    source /usr/local/share/chruby/auto.sh
 79+    _chruby_dirs
 80+else
 81+    _source_from_omz_settings
 82+    _chruby_dirs
 83+fi
 84+
 85+function ensure_chruby() {
 86+    $(whence chruby)
 87+}
 88+
 89+function current_ruby() {
 90+    local _ruby
 91+    _ruby="$(chruby |grep \* |tr -d '* ')"
 92+    if [[ $(chruby |grep -c \*) -eq 1 ]]; then
 93+        echo ${_ruby}
 94+    else
 95+        echo "system"
 96+    fi
 97+}
 98+
 99+function chruby_prompt_info() {
100+    echo "$(current_ruby)"
101+}
102+
103+# complete on installed rubies
104+_chruby() { compadd $(chruby | tr -d '* ') }
105+compdef _chruby chruby