7b12fa9799edf07547cf5a55cf6518a4cb4c4852

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

Message

style(rbfu): clean up code

Diff

 1diff --git a/plugins/rbfu/README.md b/plugins/rbfu/README.md
 2index f1f9fa2f719fec6fcb57c7c11afa04226df01513..fbcab64deb074f2d769744a16f4fce5df7a4c736 100644
 3--- a/plugins/rbfu/README.md
 4+++ b/plugins/rbfu/README.md
 5@@ -4,6 +4,7 @@ This plugin starts [rbfu](https://github.com/hmans/rbfu), a minimal Ruby version
 6 manager, and adds some useful functions.
 7 
 8 To use it, add `rbfu` to the plugins array in your zshrc file:
 9+
10 ```zsh
11 plugins=(... rbfu)
12 ```
13diff --git a/plugins/rbfu/rbfu.plugin.zsh b/plugins/rbfu/rbfu.plugin.zsh
14index 0084852054d3c78856b24187a2e485d02b5e04c8..c973fbf9fb868ba1cc08484b184d5e5d6a4e6e8f 100644
15--- a/plugins/rbfu/rbfu.plugin.zsh
16+++ b/plugins/rbfu/rbfu.plugin.zsh
17@@ -5,38 +5,44 @@
18 # rvm_prompt_info function to return the $RBFU_RUBY_VERSION
19 # version.
20 
21-command -v rbfu &>/dev/null
22-
23-if [[ $? -eq 0 ]]; then
24-  eval "$(rbfu --init --auto)"
25-
26-  # Internal: Print ruby version details, if it's currently
27-  # active etc.
28-  function _rbfu_rubies_print() {
29-    local rb rb_out
30-    rb=$(basename $1)
31-    rb_out="$rb"
32-    [[ -h $1 ]] && rb_out="$rb_out${fg[green]}@${reset_color}"
33-    [[ "x$rb" == "x$2" ]] && rb_out="${fg[red]}$rb_out ${fg[red]}*${reset_color}"
34-    echo $rb_out
35-  }
36-
37-  # Public: Provide a list with all available rubies, this basically depends
38-  # on `ls -1` and .rfbu/rubies. Highlights the currently active ruby version
39-  # and aliases.
40-  function rbfu-rubies() {
41-    local rbfu_dir active_rb
42-    rbfu_dir=$RBFU_RUBIES
43-    active_rb=$RBFU_RUBY_VERSION
44-    [[ -z "$rbfu_dir" ]] && rbfu_dir="${HOME}/.rbfu/rubies"
45-    [[ -z "$active_rb" ]] && active_rb="system"
46-    _rbfu_rubies_print "${rbfu_dir}/system" $active_rb
47-    for rb in $(ls -1 $rbfu_dir); do
48-      _rbfu_rubies_print "${rbfu_dir}/${rb}" $active_rb
49-    done
50-  }
51-
52-  # Public: Create rvm_prompt_info command for themes compatibility, unless
53-  # it has already been defined.
54-  [ ! -x rvm_prompt_info ] && function rvm_prompt_info() { echo "${RBFU_RUBY_VERSION:=system}" }
55-fi
56+command -v rbfu &>/dev/null || return
57+
58+eval "$(rbfu --init --auto)"
59+
60+# Internal: Print ruby version details, if it's currently active, etc.
61+function _rbfu_rubies_print() {
62+  # 1: path to ruby file
63+  # 2: active ruby
64+  local rb rb_out
65+  rb="${$1:t}"
66+  rb_out="$rb"
67+
68+  # If the ruby is a symlink, add @ to the name.
69+  if [[ -h "$1" ]]; then
70+    rb_out="${rb_out}${fg[green]}@${reset_color}"
71+  fi
72+
73+  # If the ruby is active, add * to the name and show it in red.
74+  if [[ "$rb" = "$2" ]]; then
75+    rb_out="${fg[red]}${rb_out} ${fg[red]}*${reset_color}"
76+  fi
77+
78+  echo $rb_out
79+}
80+
81+# Public: Provide a list with all available rubies, this basically depends
82+# on ~/.rfbu/rubies. Highlights the currently active ruby version and aliases.
83+function rbfu-rubies() {
84+  local rbfu_dir active_rb
85+  rbfu_dir="${RBFU_RUBIES:-${HOME}/.rbfu/rubies}"
86+  active_rb="${RBFU_RUBY_VERSION:-system}"
87+
88+  _rbfu_rubies_print "${rbfu_dir}/system" "$active_rb"
89+  for rb in ${rbfu_dir}/*(N); do
90+    _rbfu_rubies_print "$rb" "$active_rb"
91+  done
92+}
93+
94+# Public: Create rvm_prompt_info command for themes compatibility, unless
95+# it has already been defined.
96+[ ! -x rvm_prompt_info ] && function rvm_prompt_info() { echo "${RBFU_RUBY_VERSION:=system}" }