From cedbb16256d5056d9f81a2b9abfc469a04ecb292 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 ed0e0b3..ec2f31d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1857,12 +1857,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 *"; @@ -1877,13 +1879,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; @@ -1900,8 +1904,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) { @@ -1910,11 +1913,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 646d694379691ac1ecdeb769365e29bafb2ed1fc 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 ec2f31d..371ff79 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1879,14 +1879,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]) { @@ -1895,6 +1892,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; @@ -1916,8 +1921,8 @@ BEGIN { output[m++] = formatted; } - for (m in output) { - print output[m] + for (n = 1; n < m; n++) { + print output[n] } exit From cc2222cb1b53cfe6ac419cf95f2ccd4f071f1b26 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 b3148ae5c06ef18702b630cb0c6774a419ec25a0 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 76c41c68b4f5142333b01831d7c356b0659a8226 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 371ff79..6a390fb 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1857,7 +1857,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 c6492fd8adef3ad446b7e719d6c8f9a003f8eba1 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 ea56ffda301f239c40004ce842546633bb0a090e 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 1fbd8ca3dddc27b4a4122fccdd20e3eb44f2eeb4 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 6a390fb..c5da6d1 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1864,6 +1864,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 *"; @@ -1880,6 +1881,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); @@ -1892,10 +1894,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 1f1ea6f88cde66c56392b9bca7651c66ef2987e2 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 c5da6d1..69af61e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3092,6 +3092,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' @@ -4108,6 +4109,7 @@ nvm() { ;; "ls-remote" | "list-remote") local NVM_LTS + local NVM_MIN="${NVM_MIN-}" local PATTERN local NVM_NO_COLORS @@ -4120,6 +4122,9 @@ nvm() { --lts=*) NVM_LTS="${1##--lts=}" ;; + --min=*) + NVM_MIN="${1##--min=}" + ;; --no-colors) NVM_NO_COLORS="${1}" ;; --*) nvm_err "Unsupported option \"${1}\"." From 5cffcaf8f20f5b32b4275ac26fd58b07529dc85b 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 69af61e..cb9af85 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4109,7 +4109,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 794881332db784fd76678fc219bbdee771fc47b5 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 cb9af85..cbf8e31 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4109,10 +4109,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 b145f236a816a96b1bc5651d36cfdad51dba8caf 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 dbf7c3ed3c57b3cfa432acdf395baf49cfd4a302 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 cbf8e31..44df30f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1857,7 +1857,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" \ @@ -1880,7 +1880,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:]]+"); @@ -1897,7 +1897,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 ae8b033db9601de2901d440252b471da29bdf7b9 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 c6bb417804c86a8f74e49b60c78e55938b07470e 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 44df30f..eb97e52 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1929,6 +1929,10 @@ BEGIN { print output[n] } + if (rows > --m) { + printf("[INFO] showing %d (of %d) versions.\n", m, rows) > "/dev/stderr" + } + exit }' } From 3dd8beb6eab40d11c3ce8b13dc89496f9e60aba8 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 eb97e52..2b360db 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1862,79 +1862,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() {