1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-11 00:10:08 +00:00

style(rbfu): clean up code

This commit is contained in:
Marc Cornellà 2021-12-13 12:14:45 +01:00
parent e3bb6e685d
commit 7b12fa9799
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B
2 changed files with 38 additions and 31 deletions

View file

@ -4,6 +4,7 @@ This plugin starts [rbfu](https://github.com/hmans/rbfu), a minimal Ruby version
manager, and adds some useful functions. manager, and adds some useful functions.
To use it, add `rbfu` to the plugins array in your zshrc file: To use it, add `rbfu` to the plugins array in your zshrc file:
```zsh ```zsh
plugins=(... rbfu) plugins=(... rbfu)
``` ```

View file

@ -5,38 +5,44 @@
# rvm_prompt_info function to return the $RBFU_RUBY_VERSION # rvm_prompt_info function to return the $RBFU_RUBY_VERSION
# version. # version.
command -v rbfu &>/dev/null command -v rbfu &>/dev/null || return
if [[ $? -eq 0 ]]; then eval "$(rbfu --init --auto)"
eval "$(rbfu --init --auto)"
# Internal: Print ruby version details, if it's currently # Internal: Print ruby version details, if it's currently active, etc.
# active etc. function _rbfu_rubies_print() {
function _rbfu_rubies_print() { # 1: path to ruby file
local rb rb_out # 2: active ruby
rb=$(basename $1) local rb rb_out
rb_out="$rb" rb="${$1:t}"
[[ -h $1 ]] && rb_out="$rb_out${fg[green]}@${reset_color}" rb_out="$rb"
[[ "x$rb" == "x$2" ]] && rb_out="${fg[red]}$rb_out ${fg[red]}*${reset_color}"
echo $rb_out
}
# Public: Provide a list with all available rubies, this basically depends # If the ruby is a symlink, add @ to the name.
# on `ls -1` and .rfbu/rubies. Highlights the currently active ruby version if [[ -h "$1" ]]; then
# and aliases. rb_out="${rb_out}${fg[green]}@${reset_color}"
function rbfu-rubies() { fi
local rbfu_dir active_rb
rbfu_dir=$RBFU_RUBIES
active_rb=$RBFU_RUBY_VERSION
[[ -z "$rbfu_dir" ]] && rbfu_dir="${HOME}/.rbfu/rubies"
[[ -z "$active_rb" ]] && active_rb="system"
_rbfu_rubies_print "${rbfu_dir}/system" $active_rb
for rb in $(ls -1 $rbfu_dir); do
_rbfu_rubies_print "${rbfu_dir}/${rb}" $active_rb
done
}
# Public: Create rvm_prompt_info command for themes compatibility, unless # If the ruby is active, add * to the name and show it in red.
# it has already been defined. if [[ "$rb" = "$2" ]]; then
[ ! -x rvm_prompt_info ] && function rvm_prompt_info() { echo "${RBFU_RUBY_VERSION:=system}" } rb_out="${fg[red]}${rb_out} ${fg[red]}*${reset_color}"
fi fi
echo $rb_out
}
# Public: Provide a list with all available rubies, this basically depends
# on ~/.rfbu/rubies. Highlights the currently active ruby version and aliases.
function rbfu-rubies() {
local rbfu_dir active_rb
rbfu_dir="${RBFU_RUBIES:-${HOME}/.rbfu/rubies}"
active_rb="${RBFU_RUBY_VERSION:-system}"
_rbfu_rubies_print "${rbfu_dir}/system" "$active_rb"
for rb in ${rbfu_dir}/*(N); do
_rbfu_rubies_print "$rb" "$active_rb"
done
}
# Public: Create rvm_prompt_info command for themes compatibility, unless
# it has already been defined.
[ ! -x rvm_prompt_info ] && function rvm_prompt_info() { echo "${RBFU_RUBY_VERSION:=system}" }