[Refactor] `nvm alias`: shift out the “alias”
parent
150ed490d0
commit
a3bc4d3e62
24
nvm.sh
24
nvm.sh
|
@ -2628,26 +2628,28 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
nvm_echo "$NVM_VERSION_DIR/bin/node"
|
nvm_echo "$NVM_VERSION_DIR/bin/node"
|
||||||
;;
|
;;
|
||||||
"alias" )
|
"alias" )
|
||||||
|
shift
|
||||||
|
|
||||||
local NVM_ALIAS_DIR
|
local NVM_ALIAS_DIR
|
||||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||||
command mkdir -p "$NVM_ALIAS_DIR/lts"
|
command mkdir -p "$NVM_ALIAS_DIR/lts"
|
||||||
local NVM_CURRENT
|
local NVM_CURRENT
|
||||||
NVM_CURRENT="$(nvm_ls_current)"
|
NVM_CURRENT="$(nvm_ls_current)"
|
||||||
if [ $# -le 2 ]; then
|
if [ $# -le 1 ]; then
|
||||||
local ALIAS_PATH
|
local ALIAS_PATH
|
||||||
for ALIAS_PATH in "$NVM_ALIAS_DIR/${2-}"*; do
|
for ALIAS_PATH in "$NVM_ALIAS_DIR/${1-}"*; do
|
||||||
NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH"
|
NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH"
|
||||||
done
|
done
|
||||||
|
|
||||||
local ALIAS
|
local ALIAS
|
||||||
for ALIAS in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
|
for ALIAS in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
|
||||||
if [ ! -f "$NVM_ALIAS_DIR/$ALIAS" ] && ([ $# -lt 2 ] || [ "~$ALIAS" = "~${2-}" ]); then
|
if [ ! -f "$NVM_ALIAS_DIR/$ALIAS" ] && ([ $# -lt 1 ] || [ "~$ALIAS" = "~${1-}" ]); then
|
||||||
NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "$ALIAS"
|
NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "$ALIAS"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
local LTS_ALIAS
|
local LTS_ALIAS
|
||||||
for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${2-}"*; do
|
for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${1-}"*; do
|
||||||
LTS_ALIAS="$(NVM_LTS=true nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")"
|
LTS_ALIAS="$(NVM_LTS=true nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")"
|
||||||
if [ -n "$LTS_ALIAS" ]; then
|
if [ -n "$LTS_ALIAS" ]; then
|
||||||
nvm_echo "${LTS_ALIAS-}"
|
nvm_echo "${LTS_ALIAS-}"
|
||||||
|
@ -2655,20 +2657,20 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')"
|
||||||
done
|
done
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ -z "${3-}" ]; then
|
if [ -z "${2-}" ]; then
|
||||||
nvm unalias "${2-}"
|
nvm unalias "${1-}"
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
if [ "${2#*\/}" != "${2-}" ]; then
|
if [ "${1#*\/}" != "${1-}" ]; then
|
||||||
nvm_err 'Aliases in subdirectories are not supported.'
|
nvm_err 'Aliases in subdirectories are not supported.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
VERSION="$(nvm_version "${3-}" || return 0)"
|
VERSION="$(nvm_version "${2-}" || return 0)"
|
||||||
if [ "$VERSION" = 'N/A' ]; then
|
if [ "$VERSION" = 'N/A' ]; then
|
||||||
nvm_err "! WARNING: Version '${3-}' does not exist."
|
nvm_err "! WARNING: Version '${2-}' does not exist."
|
||||||
fi
|
fi
|
||||||
nvm_make_alias "${2-}" "${3-}"
|
nvm_make_alias "${1-}" "${2-}"
|
||||||
NVM_CURRENT="${NVM_CURRENT-}" DEFAULT=false nvm_print_formatted_alias "${2-}" "${3-}" "$VERSION"
|
NVM_CURRENT="${NVM_CURRENT-}" DEFAULT=false nvm_print_formatted_alias "${1-}" "${2-}" "$VERSION"
|
||||||
;;
|
;;
|
||||||
"unalias" )
|
"unalias" )
|
||||||
local NVM_ALIAS_DIR
|
local NVM_ALIAS_DIR
|
||||||
|
|
Loading…
Reference in New Issue