Skip to content

Commit 6b307d0

Browse files
committed
[Fix] nvm alias: fix colors not showing by default
Colors were lost because `nvm_has_colors` checks `[ -t 1 ]`, which is false inside the `(...) | sort` pipeline in `nvm_list_aliases`. Evaluate `nvm_has_colors` before the pipe and propagate via `NVM_HAS_COLORS`, matching the approach used by `nvm_print_versions`. Bug introduced in 6311a0e.
1 parent 5a28ecb commit 6b307d0

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎nvm.sh‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ nvm_print_formatted_alias() {
11531153
fi
11541154
local ARROW
11551155
ARROW='->'
1156-
if nvm_has_colors; then
1156+
if [ "${NVM_HAS_COLORS-}" = 1 ] || nvm_has_colors; then
11571157
ARROW='\033[0;90m->\033[0m'
11581158
if [ "_${DEFAULT}" = '_true' ]; then
11591159
NEWLINE=" \033[${DEFAULT_COLOR}(default)\033[0m\n"
@@ -1254,11 +1254,17 @@ nvm_list_aliases() {
12541254
return $?
12551255
fi
12561256

1257+
local NVM_HAS_COLORS
1258+
NVM_HAS_COLORS=0
1259+
if nvm_has_colors; then
1260+
NVM_HAS_COLORS=1
1261+
fi
1262+
12571263
nvm_is_zsh && unsetopt local_options nomatch
12581264
(
12591265
local ALIAS_PATH
12601266
for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do
1261-
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}" &
1267+
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}" &
12621268
done
12631269
wait
12641270
) | command sort
@@ -1269,7 +1275,7 @@ nvm_list_aliases() {
12691275
{
12701276
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
12711277
if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then
1272-
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
1278+
NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_HAS_COLORS="${NVM_HAS_COLORS}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}"
12731279
fi
12741280
} &
12751281
done
@@ -1281,7 +1287,7 @@ nvm_list_aliases() {
12811287
# shellcheck disable=SC2030,SC2031 # (https://github.com/koalaman/shellcheck/issues/2217)
12821288
for ALIAS_PATH in "${NVM_ALIAS_DIR}/lts/${ALIAS}"*; do
12831289
{
1284-
LTS_ALIAS="$(NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_LTS=true nvm_print_alias_path "${NVM_ALIAS_DIR}" "${ALIAS_PATH}")"
1290+
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}")"
12851291
if [ -n "${LTS_ALIAS}" ]; then
12861292
nvm_echo "${LTS_ALIAS}"
12871293
fi

0 commit comments

Comments
 (0)