mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-10-11 00:00:13 +08:00
[Fix] nvm alias: do not drop output from background jobs on bash 3.2
bash 3.2 (macOS `/bin/bash` and `/bin/sh`) exec-optimizes a trailing `command` call inside a function run as a background job, which silently drops the output of nested command substitutions; in `nvm alias` that lost installed-alias colors and some default aliases, Running each job in an explicit subshell avoids it.
This commit is contained in:
@@ -1463,8 +1463,9 @@ nvm_list_aliases() {
|
||||
nvm_is_zsh && setopt local_options nonomatch
|
||||
(
|
||||
local ALIAS_PATH
|
||||
# background jobs are explicit subshells: bash 3.2 otherwise drops output from nested `command` calls in them
|
||||
for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do
|
||||
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}" &
|
||||
(NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}") &
|
||||
done
|
||||
wait
|
||||
) | command sort
|
||||
@@ -1472,12 +1473,12 @@ nvm_list_aliases() {
|
||||
(
|
||||
local ALIAS_NAME
|
||||
for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
|
||||
{
|
||||
(
|
||||
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
|
||||
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then
|
||||
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
|
||||
fi
|
||||
} &
|
||||
) &
|
||||
done
|
||||
wait
|
||||
) | command sort
|
||||
@@ -1486,12 +1487,12 @@ nvm_list_aliases() {
|
||||
local LTS_ALIAS
|
||||
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
|
||||
for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do
|
||||
{
|
||||
(
|
||||
LTS_ALIAS="$(NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_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
|
||||
) | command sort
|
||||
|
||||
Reference in New Issue
Block a user