diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-10 08:53:55 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-10 08:53:55 -0700 |
commit | 91ccccb4204457349fff4c55c3bb0d9c85a5e342 (patch) | |
tree | 021df0df33cf5d97ec431a0e9df71bbf4b5aa212 | |
parent | 2a62aae18916c034add5187f636ed8e439b5ec78 (diff) | |
download | rbpm-91ccccb4204457349fff4c55c3bb0d9c85a5e342.tar.gz rbpm-91ccccb4204457349fff4c55c3bb0d9c85a5e342.tar.xz |
prefer match at start of version
-rw-r--r-- | COPYING | 24 | ||||
-rw-r--r-- | README | 9 | ||||
-rwxr-xr-x | rbpm.sh | 15 |
3 files changed, 28 insertions, 20 deletions
@@ -1,21 +1,19 @@ -The MIT License (MIT) +Copyright 2014 David Vazgenovich Shakaryan -Copyright (c) 2014 David Vazgenovich Shakaryan +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. @@ -1,18 +1,19 @@ rbpm (ruby path mangler) -https://github.com/omp/rbpm +https://git.potato.am/rbpm.git/ Manage multiple Ruby installations with no black magic. NOTES rbpm only manages rubies located in the ~/.rubies directory. This - behaviour can be changed by setting the RUBIES_PATH environment + directory can be changed by setting the RUBIES_PATH environment variable to some other location. rbpm does not display information about rubies it does not manage, such as any system-wide install. - rbpm performs a substring match when selecting a ruby, using the - highest matching directory when there are multiple matches. + rbpm performs a substring match when selecting a ruby. If there are + multiple matches, it gives precedence to matches at the start of the + version. If there are still multiple, the greatest of those is used. DEPENDENCIES @@ -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}" |