From 48fe276e3635e292d6279dfcd7a87489aaf03278 Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 29 Jan 2024 21:04:48 +0800 Subject: [PATCH 01/16] show only versions newer than NVM_MIN_VER if set --- nvm.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nvm.sh b/nvm.sh index 0a10a72..3c0c83b 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1883,12 +1883,14 @@ nvm_print_versions() { fi command awk \ - -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" \ + -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min_ver="${NVM_MIN_VER:-v0}" \ -v installed_versions="$(nvm_ls | tr '\n' '|')" -v current="$NVM_CURRENT" \ -v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \ -v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \ -v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" ' function alen(arr, i, len) { len=0; for(i in arr) len++; return len; } +function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); } +function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; } BEGIN { fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *"; fmt_system = has_colors ? (system_color ? "\033[" system_color "%15s\033[0m" : "%15s") : "%15s *"; @@ -1903,13 +1905,15 @@ BEGIN { split(remote_versions, lines, "|"); split(installed_versions, installed, "|"); rows = alen(lines); - - for (n = 1; n <= rows; n++) { + filter = (min_ver != "v0"); + for (m = n = 1; n <= rows; n++) { split(lines[n], fields, "[[:blank:]]+"); cols = alen(fields); version = fields[1]; - is_installed = 0; + if (filter && comp(version, min_ver) < 0) continue; + filter = 0; + is_installed = 0; for (i in installed) { if (version == installed[i]) { is_installed = 1; @@ -1926,8 +1930,7 @@ BEGIN { fmt_version = fmt_installed; } - padding = (!has_colors && is_installed) ? "" : " "; - + padding = (is_installed && !has_colors) ? "" : " "; if (cols == 1) { formatted = sprintf(fmt_version, version); } else if (cols == 2) { @@ -1936,11 +1939,11 @@ BEGIN { formatted = sprintf((fmt_version padding fmt_latest_lts), version, fields[2]); } - output[n] = formatted; + output[m++] = formatted; } - for (n = 1; n <= rows; n++) { - print output[n] + for (m in output) { + print output[m] } exit From 37811e0d7d477cd8ace9a6ce947061dbde8f8748 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sat, 29 Jun 2024 10:18:07 +0800 Subject: [PATCH 02/16] always list installed versions --- nvm.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nvm.sh b/nvm.sh index 3c0c83b..f80714a 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1905,14 +1905,11 @@ BEGIN { split(remote_versions, lines, "|"); split(installed_versions, installed, "|"); rows = alen(lines); - filter = (min_ver != "v0"); + filter_on = (vcmp("v0.0.0", min_ver) != 0); for (m = n = 1; n <= rows; n++) { split(lines[n], fields, "[[:blank:]]+"); cols = alen(fields); version = fields[1]; - if (filter && comp(version, min_ver) < 0) continue; - - filter = 0; is_installed = 0; for (i in installed) { if (version == installed[i]) { @@ -1921,6 +1918,14 @@ BEGIN { } } + if (filter_on && !is_installed) { + if (vcmp(version, min_ver) >= 0) { + filter_on = 0; + } else { + continue; + } + } + fmt_version = "%15s"; if (version == current) { fmt_version = fmt_current; @@ -1942,8 +1947,8 @@ BEGIN { output[m++] = formatted; } - for (m in output) { - print output[m] + for (n = 1; n < m; n++) { + print output[n] } exit From c390144c1e51813a932b6c8a52427e99194d2e57 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sat, 29 Jun 2024 13:47:51 +0800 Subject: [PATCH 03/16] add test for NVM_MIN_VER support show only versions newer than NVM_MIN_VER if set --- test/fast/Unit tests/nvm_print_versions | 139 ++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 test/fast/Unit tests/nvm_print_versions diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions new file mode 100755 index 0000000..124c930 --- /dev/null +++ b/test/fast/Unit tests/nvm_print_versions @@ -0,0 +1,139 @@ +#!/bin/sh + +# shellcheck disable=SC2317 + +die () { echo "$@" ; cleanup ; exit 1; } + +cleanup() { + unset -f nvm_remote_versions nvm_ls nvm_ls_current nvm_remote_versions + if [ -n "$TEMP_NVM_MIN_VER" ]; then + export NVM_MIN_VER="$TEMP_NVM_MIN_VER" + fi +} + +\. ../../../nvm.sh + + +if [ -n "$NVM_MIN_VER" ]; then + TEMP_NVM_MIN_VER="$NVM_MIN_VER" + unset NVM_MIN_VER +fi + +# mock currently installed versions +nvm_ls() { + echo "v16.20.2 +v18.20.3 +system" +} + +# mock currently active version +nvm_ls_current() { + echo "v18.20.3" +} + +nvm_remote_versions() { + echo "v16.0.0 +v16.20.2 Gallium * +v17.0.0 +v17.9.1 +v18.0.0 +v18.1.0 +v18.20.2 Hydrogen +v18.20.3 Hydrogen * +v19.0.0 +v19.9.0 +v20.0.0 +v20.8.1 +v20.9.0 Iron * +v21.0.0 +v21.1.0" +} + + +# nvm_print_versions should print all versions from nvm_remote_versions +OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)")" +EXPECTED_OUTPUT=" v16.0.0 + v16.20.2 * (Latest LTS: Gallium) + v17.0.0 + v17.9.1 + v18.0.0 + v18.1.0 + v18.20.2 (LTS: Hydrogen) +-> v18.20.3 * (Latest LTS: Hydrogen) + v19.0.0 + v19.9.0 + v20.0.0 + v20.8.1 + v20.9.0 (Latest LTS: Iron) + v21.0.0 + v21.1.0" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_versions did not output all expected versions; got $OUTPUT" + + +# versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=18 nvm_print_versions "$(nvm_remote_versions)")" +EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) + v18.0.0 + v18.1.0 + v18.20.2 (LTS: Hydrogen) +-> v18.20.3 * (Latest LTS: Hydrogen) + v19.0.0 + v19.9.0 + v20.0.0 + v20.8.1 + v20.9.0 (Latest LTS: Iron) + v21.0.0 + v21.1.0" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=18 nvm_print_versions did not output all expected versions; got $OUTPUT" + + +# versions lower than 19 should be filtered out +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=19 nvm_print_versions "$(nvm_remote_versions)")" +EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) +-> v18.20.3 * (Latest LTS: Hydrogen) + v19.0.0 + v19.9.0 + v20.0.0 + v20.8.1 + v20.9.0 (Latest LTS: Iron) + v21.0.0 + v21.1.0" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=19 nvm_print_versions did not output all expected versions; got $OUTPUT" + + +# versions lower than 20.1 should be filtered out, so v20.0.0 is out +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)")" +EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) +-> v18.20.3 * (Latest LTS: Hydrogen) + v20.8.1 + v20.9.0 (Latest LTS: Iron) + v21.0.0 + v21.1.0" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" + + +# assume v18.20.3 is NOT installed, so now it should be filtered out +nvm_ls() { + echo "v16.20.2 +system" +} + +nvm_ls_current() { + echo "v16.20.2" +} + +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)")" +EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium) + v20.8.1 + v20.9.0 (Latest LTS: Iron) + v21.0.0 + v21.1.0" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" + + +cleanup From 9f4dd6477a7a40918bd2a1ef78e537be798b05ce Mon Sep 17 00:00:00 2001 From: ryenus Date: Sat, 29 Jun 2024 13:17:25 +0800 Subject: [PATCH 04/16] trim leading space in mock output due to eclint errors --- test/fast/Unit tests/nvm_print_versions | 94 ++++++++++++------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index 124c930..dc12d55 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -51,67 +51,67 @@ v21.1.0" # nvm_print_versions should print all versions from nvm_remote_versions -OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)")" -EXPECTED_OUTPUT=" v16.0.0 - v16.20.2 * (Latest LTS: Gallium) - v17.0.0 - v17.9.1 - v18.0.0 - v18.1.0 - v18.20.2 (LTS: Hydrogen) +OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +EXPECTED_OUTPUT="v16.0.0 +v16.20.2 * (Latest LTS: Gallium) +v17.0.0 +v17.9.1 +v18.0.0 +v18.1.0 +v18.20.2 (LTS: Hydrogen) -> v18.20.3 * (Latest LTS: Hydrogen) - v19.0.0 - v19.9.0 - v20.0.0 - v20.8.1 - v20.9.0 (Latest LTS: Iron) - v21.0.0 - v21.1.0" +v19.0.0 +v19.9.0 +v20.0.0 +v20.8.1 +v20.9.0 (Latest LTS: Iron) +v21.0.0 +v21.1.0" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=18 nvm_print_versions "$(nvm_remote_versions)")" -EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) - v18.0.0 - v18.1.0 - v18.20.2 (LTS: Hydrogen) +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) +v18.0.0 +v18.1.0 +v18.20.2 (LTS: Hydrogen) -> v18.20.3 * (Latest LTS: Hydrogen) - v19.0.0 - v19.9.0 - v20.0.0 - v20.8.1 - v20.9.0 (Latest LTS: Iron) - v21.0.0 - v21.1.0" +v19.0.0 +v19.9.0 +v20.0.0 +v20.8.1 +v20.9.0 (Latest LTS: Iron) +v21.0.0 +v21.1.0" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=18 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 19 should be filtered out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=19 nvm_print_versions "$(nvm_remote_versions)")" -EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) - v19.0.0 - v19.9.0 - v20.0.0 - v20.8.1 - v20.9.0 (Latest LTS: Iron) - v21.0.0 - v21.1.0" +v19.0.0 +v19.9.0 +v20.0.0 +v20.8.1 +v20.9.0 (Latest LTS: Iron) +v21.0.0 +v21.1.0" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=19 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 20.1 should be filtered out, so v20.0.0 is out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)")" -EXPECTED_OUTPUT=" v16.20.2 * (Latest LTS: Gallium) +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) - v20.8.1 - v20.9.0 (Latest LTS: Iron) - v21.0.0 - v21.1.0" +v20.8.1 +v20.9.0 (Latest LTS: Iron) +v21.0.0 +v21.1.0" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" @@ -126,12 +126,12 @@ nvm_ls_current() { echo "v16.20.2" } -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)")" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium) - v20.8.1 - v20.9.0 (Latest LTS: Iron) - v21.0.0 - v21.1.0" +v20.8.1 +v20.9.0 (Latest LTS: Iron) +v21.0.0 +v21.1.0" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" From b16b4ee6adb532ff98d69cb830e8291f93a43ac4 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sun, 30 Jun 2024 01:50:15 +0800 Subject: [PATCH 05/16] rename NVM_MIN_VER to NVM_MIN since nvm is all about versions, so no need for the explicit suffix. --- nvm.sh | 2 +- test/fast/Unit tests/nvm_print_versions | 26 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/nvm.sh b/nvm.sh index f80714a..29a8d78 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1883,7 +1883,7 @@ nvm_print_versions() { fi command awk \ - -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min_ver="${NVM_MIN_VER:-v0}" \ + -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min_ver="${NVM_MIN:-v0}" \ -v installed_versions="$(nvm_ls | tr '\n' '|')" -v current="$NVM_CURRENT" \ -v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \ -v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \ diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index dc12d55..39113ec 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -6,17 +6,17 @@ die () { echo "$@" ; cleanup ; exit 1; } cleanup() { unset -f nvm_remote_versions nvm_ls nvm_ls_current nvm_remote_versions - if [ -n "$TEMP_NVM_MIN_VER" ]; then - export NVM_MIN_VER="$TEMP_NVM_MIN_VER" + if [ -n "$TEMP_NVM_MIN" ]; then + export NVM_MIN="$TEMP_NVM_MIN" fi } \. ../../../nvm.sh -if [ -n "$NVM_MIN_VER" ]; then - TEMP_NVM_MIN_VER="$NVM_MIN_VER" - unset NVM_MIN_VER +if [ -n "$NVM_MIN" ]; then + TEMP_NVM_MIN="$NVM_MIN" + unset NVM_MIN fi # mock currently installed versions @@ -72,7 +72,7 @@ v21.1.0" # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) v18.0.0 v18.1.0 @@ -86,11 +86,11 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=18 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 19 should be filtered out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) v19.0.0 @@ -101,11 +101,11 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=19 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 20.1 should be filtered out, so v20.0.0 is out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) v20.8.1 @@ -113,7 +113,7 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" # assume v18.20.3 is NOT installed, so now it should be filtered out @@ -126,14 +126,14 @@ nvm_ls_current() { echo "v16.20.2" } -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN_VER=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium) v20.8.1 v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN_VER=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" cleanup From f2b7583b6b65d828a4080e4b8e952963b57539d0 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sun, 30 Jun 2024 10:46:11 +0800 Subject: [PATCH 06/16] prefixed versions like v18 also work --- test/fast/Unit tests/nvm_print_versions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index 39113ec..c042068 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -72,7 +72,7 @@ v21.1.0" # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) v18.0.0 v18.1.0 @@ -105,7 +105,7 @@ v21.1.0" # versions lower than 20.1 should be filtered out, so v20.0.0 is out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) v20.8.1 From 858eda58c4db2f07810ef5ceaf9b1f06b6c680b9 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sun, 14 Jul 2024 11:45:52 +0800 Subject: [PATCH 07/16] remove function ref duplication --- test/fast/Unit tests/nvm_print_versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index c042068..b9d22b8 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -5,7 +5,7 @@ die () { echo "$@" ; cleanup ; exit 1; } cleanup() { - unset -f nvm_remote_versions nvm_ls nvm_ls_current nvm_remote_versions + unset -f nvm_remote_versions nvm_ls nvm_ls_current if [ -n "$TEMP_NVM_MIN" ]; then export NVM_MIN="$TEMP_NVM_MIN" fi From 54a5777ff87326fd1568ff887a45ed30bd9cfe01 Mon Sep 17 00:00:00 2001 From: ryenus Date: Sun, 14 Jul 2024 14:18:11 +0800 Subject: [PATCH 08/16] always show updates for installed versions even if they're older than $NVM_MIN --- nvm.sh | 10 ++++++--- test/fast/Unit tests/nvm_print_versions | 28 +++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/nvm.sh b/nvm.sh index 29a8d78..d81188b 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1890,6 +1890,7 @@ nvm_print_versions() { -v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" ' function alen(arr, i, len) { len=0; for(i in arr) len++; return len; } function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); } +function v2m(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); return a[1]; } function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; } BEGIN { fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *"; @@ -1906,6 +1907,7 @@ BEGIN { split(installed_versions, installed, "|"); rows = alen(lines); filter_on = (vcmp("v0.0.0", min_ver) != 0); + current_major = -1; for (m = n = 1; n <= rows; n++) { split(lines[n], fields, "[[:blank:]]+"); cols = alen(fields); @@ -1918,10 +1920,12 @@ BEGIN { } } - if (filter_on && !is_installed) { - if (vcmp(version, min_ver) >= 0) { + if (filter_on != 0) { + if (is_installed) { + current_major = v2m(version); + } else if (vcmp(version, min_ver) >= 0) { filter_on = 0; - } else { + } else if (v2m(version) != current_major) { continue; } } diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index b9d22b8..3e21498 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -33,7 +33,8 @@ nvm_ls_current() { nvm_remote_versions() { echo "v16.0.0 -v16.20.2 Gallium * +v16.20.2 Gallium +v16.20.3 Gallium * v17.0.0 v17.9.1 v18.0.0 @@ -53,7 +54,8 @@ v21.1.0" # nvm_print_versions should print all versions from nvm_remote_versions OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.0.0 -v16.20.2 * (Latest LTS: Gallium) +v16.20.2 * (LTS: Gallium) +v16.20.3 (Latest LTS: Gallium) v17.0.0 v17.9.1 v18.0.0 @@ -68,12 +70,13 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(1) nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" -EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) +EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) +v16.20.3 (Latest LTS: Gallium) v18.0.0 v18.1.0 v18.20.2 (LTS: Hydrogen) @@ -86,12 +89,13 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(2) NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 19 should be filtered out OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" -EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) +EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) +v16.20.3 (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) v19.0.0 v19.9.0 @@ -101,19 +105,20 @@ v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(3) NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT" # versions lower than 20.1 should be filtered out, so v20.0.0 is out OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" -EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium) +EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) +v16.20.3 (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) v20.8.1 v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(4) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" # assume v18.20.3 is NOT installed, so now it should be filtered out @@ -127,13 +132,14 @@ nvm_ls_current() { } OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" -EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium) +EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium) +v16.20.3 (Latest LTS: Gallium) v20.8.1 v20.9.0 (Latest LTS: Iron) v21.0.0 v21.1.0" -[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(5) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" cleanup From 594f8c0a808187e7d8d444788eeea9f2de356f9e Mon Sep 17 00:00:00 2001 From: ryenus Date: Sun, 14 Jul 2024 18:43:55 +0800 Subject: [PATCH 09/16] ls-remote: add CLI option --min= When omitted, fallback to the environment variable "NVM_MIN" if set. And the CLI option --min= takes precedence over the environment variable "NVM_MIN" if both are present. --- nvm.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nvm.sh b/nvm.sh index d81188b..ac957b7 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3118,6 +3118,7 @@ nvm() { nvm_echo ' nvm ls-remote [] List remote versions available for install, matching a given if provided' nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' --lts= When listing, only show versions for a specific LTS line' + nvm_echo ' --min= When listing, only show versions greater than or equal to , including minor/patch updates for installed versions' nvm_echo ' --no-colors Suppress colored output' nvm_echo ' nvm version Resolve the given description to a single local version' nvm_echo ' nvm version-remote Resolve the given description to a single remote version' @@ -4134,6 +4135,7 @@ nvm() { ;; "ls-remote" | "list-remote") local NVM_LTS + local NVM_MIN="${NVM_MIN-}" local PATTERN local NVM_NO_COLORS @@ -4146,6 +4148,9 @@ nvm() { --lts=*) NVM_LTS="${1##--lts=}" ;; + --min=*) + NVM_MIN="${1##--min=}" + ;; --no-colors) NVM_NO_COLORS="${1}" ;; --*) nvm_err "Unsupported option \"${1}\"." From e71918ec8c12fa37ab496a5dd203871f3f183a28 Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 15 Jul 2024 14:45:57 +0800 Subject: [PATCH 10/16] avoid inline initialization for ksh compatibility Co-authored-by: Jordan Harband --- nvm.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index ac957b7..16bb3c7 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4135,7 +4135,8 @@ nvm() { ;; "ls-remote" | "list-remote") local NVM_LTS - local NVM_MIN="${NVM_MIN-}" + local NVM_MIN + NVM_MIN="${NVM_MIN-}" local PATTERN local NVM_NO_COLORS From c02964100e5ba3c684782abdc7eb224ffd4c3a6c Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 15 Jul 2024 14:55:33 +0800 Subject: [PATCH 11/16] ls-remote: introduce temp var for env inheritance This is to inherit $NVM_MIN from env when defined, meanwhile avoiding inline local variable initialization for ksh compatibility. Co-authored-by: Jordan Harband --- nvm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 16bb3c7..aeafa30 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4135,10 +4135,12 @@ nvm() { ;; "ls-remote" | "list-remote") local NVM_LTS - local NVM_MIN - NVM_MIN="${NVM_MIN-}" local PATTERN local NVM_NO_COLORS + local NVM_MIN_ENV + NVM_MIN_ENV="${NVM_MIN-}" + local NVM_MIN + NVM_MIN="${NVM_MIN_ENV-}" while [ $# -gt 0 ]; do case "${1-}" in From f99c9f30cd69c9381202fbc3ae9bb7cd0143cefc Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 15 Jul 2024 15:19:15 +0800 Subject: [PATCH 12/16] [test] avoid leaking temp variable --- test/fast/Unit tests/nvm_print_versions | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index 3e21498..39c7137 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -8,6 +8,7 @@ cleanup() { unset -f nvm_remote_versions nvm_ls nvm_ls_current if [ -n "$TEMP_NVM_MIN" ]; then export NVM_MIN="$TEMP_NVM_MIN" + unset TEMP_NVM_MIN fi } From 206a14297cd96e7f76eb29dad61b51d77e819b67 Mon Sep 17 00:00:00 2001 From: ryenus Date: Tue, 30 Jul 2024 08:07:04 +0800 Subject: [PATCH 13/16] rename min_ver to min for consistency --- nvm.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index aeafa30..4f94133 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1883,7 +1883,7 @@ nvm_print_versions() { fi command awk \ - -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min_ver="${NVM_MIN:-v0}" \ + -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min="${NVM_MIN:-v0}" \ -v installed_versions="$(nvm_ls | tr '\n' '|')" -v current="$NVM_CURRENT" \ -v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \ -v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \ @@ -1906,7 +1906,7 @@ BEGIN { split(remote_versions, lines, "|"); split(installed_versions, installed, "|"); rows = alen(lines); - filter_on = (vcmp("v0.0.0", min_ver) != 0); + filter_on = (vcmp("v0.0.0", min) != 0); current_major = -1; for (m = n = 1; n <= rows; n++) { split(lines[n], fields, "[[:blank:]]+"); @@ -1923,7 +1923,7 @@ BEGIN { if (filter_on != 0) { if (is_installed) { current_major = v2m(version); - } else if (vcmp(version, min_ver) >= 0) { + } else if (vcmp(version, min) >= 0) { filter_on = 0; } else if (v2m(version) != current_major) { continue; From dd28eb493265ab7571dbf34eecadecd34f10c570 Mon Sep 17 00:00:00 2001 From: ryenus Date: Tue, 30 Jul 2024 08:07:29 +0800 Subject: [PATCH 14/16] set NVM_NO_COLORS to --no-colors to disable color --- test/fast/Unit tests/nvm_print_versions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/fast/Unit tests/nvm_print_versions b/test/fast/Unit tests/nvm_print_versions index 39c7137..f1fabee 100755 --- a/test/fast/Unit tests/nvm_print_versions +++ b/test/fast/Unit tests/nvm_print_versions @@ -53,7 +53,7 @@ v21.1.0" # nvm_print_versions should print all versions from nvm_remote_versions -OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS='--no-colors' nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.0.0 v16.20.2 * (LTS: Gallium) v16.20.3 (Latest LTS: Gallium) @@ -75,7 +75,7 @@ v21.1.0" # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) v16.20.3 (Latest LTS: Gallium) v18.0.0 @@ -94,7 +94,7 @@ v21.1.0" # versions lower than 19 should be filtered out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) v16.20.3 (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) @@ -110,7 +110,7 @@ v21.1.0" # versions lower than 20.1 should be filtered out, so v20.0.0 is out -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) v16.20.3 (Latest LTS: Gallium) -> v18.20.3 * (Latest LTS: Hydrogen) @@ -132,7 +132,7 @@ nvm_ls_current() { echo "v16.20.2" } -OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" +OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium) v16.20.3 (Latest LTS: Gallium) v20.8.1 From fc4a98b7712e377eee0bc6f123a41c1eae1c00b4 Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 23 Dec 2024 10:02:43 +0800 Subject: [PATCH 15/16] display a hint when version filtering is in effect due the use of --min or NVM_MIN, which would show only the versions higher than the specified min version, and/or the available minor/patch updates for the installed versions. --- nvm.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nvm.sh b/nvm.sh index 4f94133..facad4f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1955,6 +1955,10 @@ BEGIN { print output[n] } + if (rows > --m) { + printf("[INFO] showing %d (of %d) versions.\n", m, rows) > "/dev/stderr" + } + exit }' } From f28584cecfc1641c44957cc4da6aadec7fd9e0bd Mon Sep 17 00:00:00 2001 From: ryenus Date: Mon, 23 Dec 2024 10:07:06 +0800 Subject: [PATCH 16/16] indent awk script properly --- nvm.sh | 122 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/nvm.sh b/nvm.sh index facad4f..2b3454f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1888,79 +1888,79 @@ nvm_print_versions() { -v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \ -v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \ -v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" ' -function alen(arr, i, len) { len=0; for(i in arr) len++; return len; } -function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); } -function v2m(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); return a[1]; } -function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; } -BEGIN { - fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *"; - fmt_system = has_colors ? (system_color ? "\033[" system_color "%15s\033[0m" : "%15s") : "%15s *"; - fmt_current = has_colors ? (current_color ? "\033[" current_color "->%13s\033[0m" : "%15s") : "->%13s *"; + function alen(arr, i, len) { len=0; for(i in arr) len++; return len; } + function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); } + function v2m(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); return a[1]; } + function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; } + BEGIN { + fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *"; + fmt_system = has_colors ? (system_color ? "\033[" system_color "%15s\033[0m" : "%15s") : "%15s *"; + fmt_current = has_colors ? (current_color ? "\033[" current_color "->%13s\033[0m" : "%15s") : "->%13s *"; - latest_lts_color = current_color; - sub(/0;/, "1;", latest_lts_color); + latest_lts_color = current_color; + sub(/0;/, "1;", latest_lts_color); - fmt_latest_lts = has_colors && latest_lts_color ? ("\033[" latest_lts_color " (Latest LTS: %s)\033[0m") : " (Latest LTS: %s)"; - fmt_old_lts = has_colors && old_lts_color ? ("\033[" old_lts_color " (LTS: %s)\033[0m") : " (LTS: %s)"; + fmt_latest_lts = has_colors && latest_lts_color ? ("\033[" latest_lts_color " (Latest LTS: %s)\033[0m") : " (Latest LTS: %s)"; + fmt_old_lts = has_colors && old_lts_color ? ("\033[" old_lts_color " (LTS: %s)\033[0m") : " (LTS: %s)"; - split(remote_versions, lines, "|"); - split(installed_versions, installed, "|"); - rows = alen(lines); - filter_on = (vcmp("v0.0.0", min) != 0); - current_major = -1; - for (m = n = 1; n <= rows; n++) { - split(lines[n], fields, "[[:blank:]]+"); - cols = alen(fields); - version = fields[1]; - is_installed = 0; - for (i in installed) { - if (version == installed[i]) { - is_installed = 1; - break; + split(remote_versions, lines, "|"); + split(installed_versions, installed, "|"); + rows = alen(lines); + filter_on = (vcmp("v0.0.0", min) != 0); + current_major = -1; + for (m = n = 1; n <= rows; n++) { + split(lines[n], fields, "[[:blank:]]+"); + cols = alen(fields); + version = fields[1]; + is_installed = 0; + for (i in installed) { + if (version == installed[i]) { + is_installed = 1; + break; + } } - } - if (filter_on != 0) { - if (is_installed) { - current_major = v2m(version); - } else if (vcmp(version, min) >= 0) { - filter_on = 0; - } else if (v2m(version) != current_major) { - continue; + if (filter_on != 0) { + if (is_installed) { + current_major = v2m(version); + } else if (vcmp(version, min) >= 0) { + filter_on = 0; + } else if (v2m(version) != current_major) { + continue; + } } + + fmt_version = "%15s"; + if (version == current) { + fmt_version = fmt_current; + } else if (version == "system") { + fmt_version = fmt_system; + } else if (is_installed) { + fmt_version = fmt_installed; + } + + padding = (is_installed && !has_colors) ? "" : " "; + if (cols == 1) { + formatted = sprintf(fmt_version, version); + } else if (cols == 2) { + formatted = sprintf((fmt_version padding fmt_old_lts), version, fields[2]); + } else if (cols == 3 && fields[3] == "*") { + formatted = sprintf((fmt_version padding fmt_latest_lts), version, fields[2]); + } + + output[m++] = formatted; } - fmt_version = "%15s"; - if (version == current) { - fmt_version = fmt_current; - } else if (version == "system") { - fmt_version = fmt_system; - } else if (is_installed) { - fmt_version = fmt_installed; + for (n = 1; n < m; n++) { + print output[n] } - padding = (is_installed && !has_colors) ? "" : " "; - if (cols == 1) { - formatted = sprintf(fmt_version, version); - } else if (cols == 2) { - formatted = sprintf((fmt_version padding fmt_old_lts), version, fields[2]); - } else if (cols == 3 && fields[3] == "*") { - formatted = sprintf((fmt_version padding fmt_latest_lts), version, fields[2]); + if (rows > --m) { + printf("[INFO] showing %d (of %d) versions.\n", m, rows) > "/dev/stderr" } - output[m++] = formatted; - } - - for (n = 1; n < m; n++) { - print output[n] - } - - if (rows > --m) { - printf("[INFO] showing %d (of %d) versions.\n", m, rows) > "/dev/stderr" - } - - exit -}' + exit + }' } nvm_validate_implicit_alias() {