Skip to content
Myr

[Fix] `nvm alias`: do not drop output from background jobs on bash 3.2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Jordan Harband · committed by Jordan Harband · parent 0add6b8 · Browse files · 1 file+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−5 removed

  • other:+6 added−5 removed

1 file+6 added−5 removed

modified:nvm.sh+6 added-5 removed
1461 unmodified lines
14621463 nvm_is_zsh && setopt local_options nonomatch1464 (1465 local ALIAS_PATH1466 # background jobs are explicit subshells: bash 3.2 otherwise drops output from nested `command` calls in them1467 for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do1467 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}" &1468 (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}") &1469 done1470 wait1471 ) | command sort14721473 (1474 local ALIAS_NAME1475 for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable" "$(nvm_iojs_prefix)"; do1475 {1476 (1477 # shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)1478 if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then1479 NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"1480 fi1480 } &1481 ) &1482 done1483 wait1484 ) | command sort14851486 (1487 local LTS_ALIAS1488 # shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)1489 for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do1489 {1490 (1491 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}")"1492 if [ -n "${LTS_ALIAS}" ]; then1493 nvm_echo "${LTS_ALIAS}"1494 fi1494 } &1495 ) &1496 done1497 wait1498 ) | command sort1499 return
3934 unmodified lines