aboutsummaryrefslogtreecommitdiff
path: root/rbpm.sh
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-10 08:53:55 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-10 08:53:55 -0700
commit91ccccb4204457349fff4c55c3bb0d9c85a5e342 (patch)
tree021df0df33cf5d97ec431a0e9df71bbf4b5aa212 /rbpm.sh
parent2a62aae18916c034add5187f636ed8e439b5ec78 (diff)
downloadrbpm-91ccccb4204457349fff4c55c3bb0d9c85a5e342.tar.gz
rbpm-91ccccb4204457349fff4c55c3bb0d9c85a5e342.tar.xz
prefer match at start of version
Diffstat (limited to 'rbpm.sh')
-rwxr-xr-xrbpm.sh15
1 files changed, 12 insertions, 3 deletions
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}"