mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 14:21:50 +00:00
show only versions newer than NVM_MIN_VER if set
This commit is contained in:
parent
99352a64d2
commit
48fe276e36
21
nvm.sh
21
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
|
||||
|
Loading…
Reference in New Issue
Block a user