From bb67f811b3eeb97de56d7d82165305257098947a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 15 Jun 2014 03:27:19 -0700 Subject: Code organisation. --- rpath.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'rpath.sh') diff --git a/rpath.sh b/rpath.sh index da15706..ad31310 100755 --- a/rpath.sh +++ b/rpath.sh @@ -24,7 +24,7 @@ _echo() { echo "echo '${@//\'/\'\\\'\'}'" } -_export_path() { +_export() { echo "export PATH='${PATH//\'/\'\\\'\'}'" echo "hash -r" } @@ -52,16 +52,6 @@ _populate_dirs() { [[ -n "${dirs}" ]] || _die "directory ${RUBIES_PATH} is empty." } -_match() { - if [[ "${1}" =~ ^[0-9]+$ ]]; then - [[ "${2}" == "${1}" ]] && return - else - [[ "${3}" == *"${1}"* ]] && return - fi - - return 1 -} - _populate_selected() { local dir dirs unset selected @@ -81,13 +71,6 @@ _populate_selected() { || _warn 'warning: multiple rubies found in PATH.' } -_set() { - _clear - _echo "Adding ${1}/bin to PATH." - - PATH="${1}/bin:${PATH}" -} - _clear() { local dir dirs cdirs @@ -106,6 +89,22 @@ _clear() { PATH="$(IFS=':'; echo "${cdirs[*]}")" } +_add() { + _echo "Adding ${1}/bin to PATH." + + PATH="${1}/bin:${PATH}" +} + +_match() { + if [[ "${1}" =~ ^[0-9]+$ ]]; then + [[ "${2}" == "${1}" ]] && return + else + [[ "${3}" == *"${1}"* ]] && return + fi + + return 1 +} + rpath_ls() { _populate_dirs _populate_selected @@ -138,8 +137,9 @@ rpath_set() { for dir in "${dirs[@]}"; do if _match "${1}" "$((++counter))" "${dir##*/}"; then - _set "${dir}" - _export_path + _clear + _add "${dir}" + _export return fi @@ -150,7 +150,7 @@ rpath_set() { rpath_clear() { _clear || _die 'no rubies found in PATH.' - _export_path + _export } rpath_help() { -- cgit v1.2.3-70-g09d2