From 60a0e7180937ef85c6a04a6c82e57c2ffab52d7a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 15 Jun 2014 00:45:04 -0700 Subject: Output warning when multiple rubies are in PATH. --- rpath.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'rpath.sh') diff --git a/rpath.sh b/rpath.sh index 1f24420..d71237c 100755 --- a/rpath.sh +++ b/rpath.sh @@ -29,8 +29,12 @@ _export_path() { echo "hash -r" } +_warn() { + echo "echo '${@//\'/\'\\\'\'}' 1>&2" +} + _die() { - [[ -n "${@}" ]] && echo "echo '${@//\'/\'\\\'\'}' 1>&2" + [[ -n "${@}" ]] && _warn "${@}" echo "false" exit 1 @@ -118,7 +122,12 @@ rpath_ls() { } rpath_get() { - current="$(_get)" && _echo "${current}" + current="$(_get)" || _die 'No rubies found in PATH.' + + [[ $(wc -l <<< "${current}") -gt 1 ]] \ + && _warn 'Warning: multiple rubies found in PATH.' + + _echo "${current}" } rpath_set() { @@ -148,11 +157,11 @@ rpath_clear() { rpath_help() { _echo 'Usage: rpath [args]' _echo - _echo 'Available options:' + _echo 'Commands:' _echo ' ls List all available rubies.' _echo ' get Display currently selected ruby.' _echo ' set Select specified ruby.' - _echo ' clear Clear path of any rpath rubies.' + _echo ' clear Clear path of any rubies.' _echo ' help Display this help information.' } -- cgit v1.2.3-70-g09d2