Compare commits

..

15 Commits

Author SHA1 Message Date
ryenus
387809f06d
Merge abda08ec3328ed571182c22f0130595a00c3ce59 into ff1257e8e3059ae01928c4261a41de2260bcd968 2024-07-30 00:07:58 +00:00
ryenus
abda08ec33 set NVM_NO_COLORS to --no-colors to disable color 2024-07-30 08:07:29 +08:00
ryenus
6c2bf69621 rename min_ver to min for consistency 2024-07-30 08:07:04 +08:00
ryenus
22dc48fa21 [test] avoid leaking temp variable 2024-07-29 11:01:37 +08:00
ryenus
03ecd5c33d 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-29 11:01:37 +08:00
ryenus
1dce063900 avoid inline initialization for ksh compatibility
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2024-07-29 11:01:37 +08:00
ryenus
ceff60c572 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-29 11:01:37 +08:00
ryenus
56142b471c always show updates for installed versions
even if they're older than $NVM_MIN
2024-07-29 11:01:37 +08:00
ryenus
35c801b1c9 remove function ref duplication 2024-07-29 11:01:23 +08:00
ryenus
159bde0ef2 prefixed versions like v18 also work 2024-07-29 11:01:23 +08:00
ryenus
5bc34992a9 rename NVM_MIN_VER to NVM_MIN
since nvm is all about versions, so no need for the explicit suffix.
2024-07-29 11:01:23 +08:00
ryenus
f20963eee8 trim leading space in mock output due to eclint errors 2024-07-29 11:01:23 +08:00
ryenus
a37da3aa48 add test for NVM_MIN_VER support
show only versions newer than NVM_MIN_VER if set
2024-07-29 11:01:23 +08:00
ryenus
5303492b87 always list installed versions 2024-07-29 11:01:23 +08:00
ryenus
5925f32a63 show only versions newer than NVM_MIN_VER if set 2024-07-29 11:01:23 +08:00
2 changed files with 8 additions and 8 deletions

6
nvm.sh
View File

@ -1837,7 +1837,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" \
@ -1860,7 +1860,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:]]+");
@ -1877,7 +1877,7 @@ BEGIN {
if (filter_on != 0) {
if (is_installed != 0) {
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;

View File

@ -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