Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show only versions newer than NVM_MIN_VER if set #3277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 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 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 *";
Expand All @@ -1753,20 +1755,27 @@ BEGIN {
split(remote_versions, lines, "|");
split(installed_versions, installed, "|");
rows = alen(lines);

for (n = 1; n <= rows; n++) {
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];
is_installed = 0;

for (i in installed) {
if (version == installed[i]) {
is_installed = 1;
break;
}
}

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;
Expand All @@ -1776,8 +1785,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,10 +1794,10 @@ BEGIN {
formatted = sprintf((fmt_version padding fmt_latest_lts), version, fields[2]);
}

output[n] = formatted;
output[m++] = formatted;
}

for (n = 1; n <= rows; n++) {
for (n=1; n < m; n++) {
print output[n]
}

Expand Down