1 ## load chruby from different locations
3 _source-from-omz-settings() {
4 local _chruby_path _chruby_auto
6 zstyle -s :omz:plugins:chruby path _chruby_path || return 1
7 zstyle -s :omz:plugins:chruby auto _chruby_auto || return 1
9 if [[ -r ${_chruby_path} ]]; then
10 source ${_chruby_path}
13 if [[ -r ${_chruby_auto} ]]; then
14 source ${_chruby_auto}
18 _source-from-homebrew() {
19 (( $+commands[brew] )) || return 1
22 # check default brew prefix
23 if [[ -h /usr/local/opt/chruby ]];then
24 _brew_prefix="/usr/local/opt/chruby"
26 # ok , it is not default prefix
27 # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
28 _brew_prefix=$(brew --prefix chruby)
31 [[ -r "$_brew_prefix" ]] || return 1
33 source $_brew_prefix/share/chruby/chruby.sh
34 source $_brew_prefix/share/chruby/auto.sh
39 for dir in "$HOME/.rubies" "$PREFIX/opt/rubies"; do
40 if [[ -d "$dir" ]]; then
47 if _source-from-omz-settings; then
49 elif [[ -r "/usr/local/share/chruby/chruby.sh" ]] ; then
50 source /usr/local/share/chruby/chruby.sh
51 source /usr/local/share/chruby/auto.sh
53 elif _source-from-homebrew; then
57 unfunction _source-from-homebrew _source-from-omz-settings _load-chruby-dirs
60 ## chruby utility functions and aliases
62 # rvm and rbenv plugins also provide this alias
65 function current_ruby() {
67 ruby="$(chruby | grep \* | tr -d '* ')"
68 if [[ $(chruby | grep -c \*) -eq 1 ]]; then
75 function chruby_prompt_info() {
76 echo "${$(current_ruby):gs/%/%%}"
79 # Complete chruby command with installed rubies
81 compadd $(chruby | tr -d '* ')
82 if PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command ruby &>/dev/null; then
87 compdef _chruby chruby
90 # Simple definition completer for ruby-build
91 if command ruby-build &> /dev/null; then
92 _ruby-build() { compadd $(ruby-build --definitions) }
93 compdef _ruby-build ruby-build