`nvm alias`: slightly speed up alias resolution.

Jordan Harband 2016-04-26 22:21:57 -07:00
parent 886cde7da5
commit 7b1a4e5126
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 11 additions and 9 deletions

20
nvm.sh
View File

@ -391,7 +391,7 @@ nvm_binary_available() {
nvm_alias() { nvm_alias() {
local ALIAS local ALIAS
ALIAS="$1" ALIAS="${1-}"
if [ -z "$ALIAS" ]; then if [ -z "$ALIAS" ]; then
echo >&2 'An alias is required.' echo >&2 'An alias is required.'
return 1 return 1
@ -2259,8 +2259,10 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
command mkdir -p "$NVM_ALIAS_DIR" command mkdir -p "$NVM_ALIAS_DIR"
if [ $# -le 2 ]; then if [ $# -le 2 ]; then
local DEST local DEST
for ALIAS_PATH in "$NVM_ALIAS_DIR"/"${2-}"*; do local ALIAS
ALIAS="$(command basename "$ALIAS_PATH")" local ALIAS_PATH
for ALIAS_PATH in "$NVM_ALIAS_DIR/${2-}"*; do
ALIAS="${ALIAS_PATH/$NVM_ALIAS_DIR\//}"
DEST="$(nvm_alias "$ALIAS" 2> /dev/null)" DEST="$(nvm_alias "$ALIAS" 2> /dev/null)"
if [ -n "$DEST" ]; then if [ -n "$DEST" ]; then
VERSION="$(nvm_version "$DEST")" VERSION="$(nvm_version "$DEST")"
@ -2291,18 +2293,18 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
fi fi
if [ -z "${3-}" ]; then if [ -z "${3-}" ]; then
command rm -f "$NVM_ALIAS_DIR/$2" command rm -f "$NVM_ALIAS_DIR/$2"
echo "$2 -> *poof*" echo "${2-} -> *poof*"
return return
fi fi
VERSION="$(nvm_version "$3")" VERSION="$(nvm_version "${3-}")"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "! WARNING: Version '$3' does not exist." >&2 echo "! WARNING: Version '${3-}' does not exist." >&2
fi fi
echo "$3" | tee "$NVM_ALIAS_DIR/$2" >/dev/null echo "$3" | tee "$NVM_ALIAS_DIR/${2-}" >/dev/null
if [ ! "_$3" = "_$VERSION" ]; then if [ ! "_$3" = "_$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)" echo "${2-} -> ${3-} (-> $VERSION)"
else else
echo "$2 -> $3" echo "${2-} -> ${3-}"
fi fi
;; ;;
"unalias" ) "unalias" )