From 91ccccb4204457349fff4c55c3bb0d9c85a5e342 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 10 Apr 2022 08:53:55 -0700 Subject: prefer match at start of version --- rbpm.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'rbpm.sh') diff --git a/rbpm.sh b/rbpm.sh index 290b9f1..619fc03 100755 --- a/rbpm.sh +++ b/rbpm.sh @@ -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}" -- cgit v1.2.3-70-g09d2