[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:
Jordan Harband
2026-09-30 15:56:49 +09:00
parent 0add6b8555
commit e2f57b733f
+6 -5
View File
@@ -1463,8 +1463,9 @@ nvm_list_aliases() {
nvm_is_zsh && setopt local_options nonomatch nvm_is_zsh && setopt local_options nonomatch
( (
local ALIAS_PATH 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 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 done
wait wait
) | command sort ) | command sort
@@ -1472,12 +1473,12 @@ nvm_list_aliases() {
( (
local ALIAS_NAME local ALIAS_NAME
for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do
{ (
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217) # shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then 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}" NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
fi fi
} & ) &
done done
wait wait
) | command sort ) | command sort
@@ -1486,12 +1487,12 @@ nvm_list_aliases() {
local LTS_ALIAS local LTS_ALIAS
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217) # shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do 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}")" 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 if [ -n "${LTS_ALIAS}" ]; then
nvm_echo "${LTS_ALIAS}" nvm_echo "${LTS_ALIAS}"
fi fi
} & ) &
done done
wait wait
) | command sort ) | command sort