Compare commits

..

13 Commits

Author SHA1 Message Date
ryenus
c9e3f0cd06
Merge 29779056708136fe30d2d37ad442482d7640fc90 into ff1257e8e3059ae01928c4261a41de2260bcd968 2024-07-29 10:24:21 +08:00
ryenus
2977905670 [test] avoid leaking temp variable 2024-07-15 15:19:15 +08:00
ryenus
dffecf89bf 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 <ljharb@gmail.com>
2024-07-15 14:55:33 +08:00
ryenus
547f50a137
avoid inline initialization for ksh compatibility
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2024-07-15 14:45:57 +08:00
ryenus
df9ec58512 ls-remote: add CLI option --min=<version>
When omitted, fallback to the environment variable "NVM_MIN" if set.
And the CLI option --min=<version> takes precedence over the environment
variable "NVM_MIN" if both are present.
2024-07-14 19:37:18 +08:00
ryenus
477d229171 always show updates for installed versions
even if they're older than $NVM_MIN
2024-07-14 14:18:11 +08:00
ryenus
ce329fbe61 remove function ref duplication 2024-07-14 11:52:15 +08:00
ryenus
b106798ad2 prefixed versions like v18 also work 2024-07-14 11:52:15 +08:00
ryenus
b2840f10d0 rename NVM_MIN_VER to NVM_MIN
since nvm is all about versions, so no need for the explicit suffix.
2024-07-14 11:52:15 +08:00
ryenus
cbe58242d8 trim leading space in mock output due to eclint errors 2024-07-14 11:52:15 +08:00
ryenus
0fc50b599a add test for NVM_MIN_VER support
show only versions newer than NVM_MIN_VER if set
2024-07-14 11:52:15 +08:00
ryenus
a95fcdc0b2 always list installed versions 2024-07-14 11:52:15 +08:00
ryenus
7a07eb7ae0 show only versions newer than NVM_MIN_VER if set 2024-07-14 11:52:15 +08:00
2 changed files with 8 additions and 8 deletions

6
nvm.sh
View File

@ -1837,7 +1837,7 @@ nvm_print_versions() {
fi fi
command awk \ command awk \
-v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min="${NVM_MIN:-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_versions="$(nvm_ls | tr '\n' '|')" -v current="$NVM_CURRENT" \
-v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \ -v installed_color="$INSTALLED_COLOR" -v system_color="$SYSTEM_COLOR" \
-v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \ -v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \
@ -1860,7 +1860,7 @@ BEGIN {
split(remote_versions, lines, "|"); split(remote_versions, lines, "|");
split(installed_versions, installed, "|"); split(installed_versions, installed, "|");
rows = alen(lines); rows = alen(lines);
filter_on = (vcmp("v0.0.0", min) != 0); filter_on = (vcmp("v0.0.0", min_ver) != 0);
current_major = -1; current_major = -1;
for (m = n = 1; n <= rows; n++) { for (m = n = 1; n <= rows; n++) {
split(lines[n], fields, "[[:blank:]]+"); split(lines[n], fields, "[[:blank:]]+");
@ -1877,7 +1877,7 @@ BEGIN {
if (filter_on != 0) { if (filter_on != 0) {
if (is_installed != 0) { if (is_installed != 0) {
current_major = v2m(version); current_major = v2m(version);
} else if (vcmp(version, min) >= 0) { } else if (vcmp(version, min_ver) >= 0) {
filter_on = 0; filter_on = 0;
} else if (v2m(version) != current_major) { } else if (v2m(version) != current_major) {
continue; continue;

View File

@ -53,7 +53,7 @@ v21.1.0"
# nvm_print_versions should print all versions from nvm_remote_versions # nvm_print_versions should print all versions from nvm_remote_versions
OUTPUT="$(NVM_NO_COLORS='--no-colors' nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
EXPECTED_OUTPUT="v16.0.0 EXPECTED_OUTPUT="v16.0.0
v16.20.2 * (LTS: Gallium) v16.20.2 * (LTS: Gallium)
v16.20.3 (Latest 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 # versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v18 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 * (LTS: Gallium) EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
v16.20.3 (Latest LTS: Gallium) v16.20.3 (Latest LTS: Gallium)
v18.0.0 v18.0.0
@ -94,7 +94,7 @@ v21.1.0"
# versions lower than 19 should be filtered out # versions lower than 19 should be filtered out
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=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 * (LTS: Gallium) EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
v16.20.3 (Latest LTS: Gallium) v16.20.3 (Latest LTS: Gallium)
-> v18.20.3 * (Latest LTS: Hydrogen) -> 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 # versions lower than 20.1 should be filtered out, so v20.0.0 is out
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v20.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 * (LTS: Gallium) EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
v16.20.3 (Latest LTS: Gallium) v16.20.3 (Latest LTS: Gallium)
-> v18.20.3 * (Latest LTS: Hydrogen) -> v18.20.3 * (Latest LTS: Hydrogen)
@ -132,7 +132,7 @@ nvm_ls_current() {
echo "v16.20.2" echo "v16.20.2"
} }
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=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 * (LTS: Gallium) EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium)
v16.20.3 (Latest LTS: Gallium) v16.20.3 (Latest LTS: Gallium)
v20.8.1 v20.8.1