diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-06-15 02:45:53 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-06-15 02:45:53 -0700 |
commit | 7cfb8b9ca2e66a79bb30e4762277dc3020aec70e (patch) | |
tree | a30dd46db6ec1f7c78b9b1e9c1f87a852845c1da | |
parent | a5816f08c8392b10ba24c4fc51e3dc886e148182 (diff) | |
download | rbpm-7cfb8b9ca2e66a79bb30e4762277dc3020aec70e.tar.gz rbpm-7cfb8b9ca2e66a79bb30e4762277dc3020aec70e.tar.xz |
Refactor code and improve warning logic.
-rwxr-xr-x | rpath.sh | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -62,21 +62,23 @@ _match() { return 1 } -_get() { - local dir dirs succeed=false +_populate_selected() { + local dir dirs + unset selected IFS=':' read -a dirs <<< "${PATH}" for dir in "${dirs[@]}"; do if [[ "${dir}" == "${RUBIES_PATH}/"* ]]; then dir="${dir%/bin}" - echo "${dir##*/}" - - succeed=true + selected+=("${dir##*/}") fi done - $succeed || return 1 + [[ -n ${selected} ]] || return 1 + + [[ "${#selected[@]}" -eq 1 ]] \ + || _warn 'warning: multiple rubies found in PATH.' } _set() { @@ -108,26 +110,25 @@ _clear() { rpath_ls() { _populate_dirs + _populate_selected counter=0 - current=$(_get | head -n 1) for dir in "${dirs[@]}"; do str=" [$((++counter))] ${dir##*/}" - [[ "${dir##*/}" == "${current}" ]] && str="${str/ /*}" + [[ "${dir##*/}" == "${selected}" ]] && str="${str/ /*}" _echo "${str}" done } rpath_get() { - current="$(_get)" || _die 'no rubies found in PATH.' - - [[ $(wc -l <<< "${current}") -gt 1 ]] \ - && _warn 'warning: multiple rubies found in PATH.' + _populate_selected || _die 'no rubies found in PATH.' - _echo "${current}" + for dir in "${selected[@]}"; do + _echo "${dir}" + done } rpath_set() { |