[Refactor] Speedup nvm_list_aliases()

Peter Dave Hello 2017-04-27 21:57:04 +08:00
parent e7b42198b4
commit d3a9272a0c
1 changed files with 31 additions and 14 deletions

45
nvm.sh
View File

@ -747,25 +747,42 @@ nvm_list_aliases() {
NVM_ALIAS_DIR="$(nvm_alias_path)"
command mkdir -p "${NVM_ALIAS_DIR}/lts"
local ALIAS_PATH
for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}"
done
(
local ALIAS_PATH
for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}" &
done
wait
) | sort
local ALIAS_NAME
for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
(
local ALIAS_NAME
for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable"; do
{
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && ([ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]); then
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
fi
} &
done
wait
ALIAS_NAME="$(nvm_iojs_prefix)"
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && ([ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]); then
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
fi
done
) | sort
local LTS_ALIAS
for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do
LTS_ALIAS="$(NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_LTS=true nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}")"
if [ -n "${LTS_ALIAS}" ]; then
nvm_echo "${LTS_ALIAS}"
fi
done
(
local LTS_ALIAS
for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do
{
LTS_ALIAS="$(NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_LTS=true nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}")"
if [ -n "${LTS_ALIAS}" ]; then
nvm_echo "${LTS_ALIAS}"
fi
} &
done
wait
) | sort
return
}