diff options
Diffstat (limited to 'rbpm.sh')
-rwxr-xr-x | rbpm.sh | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -4,7 +4,7 @@ # Distributed under the terms of the MIT License. # # rbpm (ruby path mangler) -# https://github.com/omp/rbpm +# https://git.potato.am/rbpm.git/ # Manage multiple Ruby installations with no black magic. # # In order to prevent environment pollution, the output of this script @@ -16,7 +16,7 @@ # Placing the above function inside ~/.bashrc (or equivalent) will load # it upon starting your shell. -RBPM_VERSION='0.1' +RBPM_VERSION='0.2' : ${RUBIES_PATH:="${HOME}/.rubies"} @@ -121,17 +121,26 @@ rbpm_get() { rbpm_set() { [[ -n "${1}" ]] || _die 'set command requires an argument.' - local dir dirs match + local dir dirs match match_start _populate_dirs for dir in "${dirs[@]}"; do if [[ "${dir##*/}" == *"${1}"* ]]; then match="${dir}" + + # Match from start of version is preferred. We assume the version + # is at the beginning of the directory name or following a hyphen. + # This avoids surprising behaviour like `2.1' matching `2.2.1' over + # `2.1.0'. + if [[ "${dir##*/}" == "${1}"* || "${dir##*/}" == *-"${1}"* ]]; then + match_start="${dir}" + fi fi done [[ -n "${match}" ]] || _die 'no matching ruby found.' + [[ -n "${match_start}" ]] && match="${match_start}" _clear _add "${match}" |