Skip to content

Commit

Permalink
show only versions newer than NVM_MIN_VER if set
Browse files Browse the repository at this point in the history
  • Loading branch information
ryenus committed Jan 29, 2024
1 parent 4e2a71b commit 28444c5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1733,12 +1733,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, s) { s=v; sub(/^(iojs-)?v/, "", s); split(s, a, "."); }
function comp(v1,v2,d,a1,a2,i) { v2a(v1,a1); v2a(v2,a2); for(i in a1) d[i] = a1[i] - a2[i]; for(i in d) { if(d[i] != 0) return d[i]}; 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 *";
Expand All @@ -1753,13 +1755,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;
Expand All @@ -1776,8 +1780,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) {
Expand All @@ -1786,11 +1789,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
Expand Down

0 comments on commit 28444c5

Please sign in to comment.