@@ -1740,7 +1740,7 @@ nvm_print_versions() {
17401740 -v old_lts_color=" $DEFAULT_COLOR " -v has_colors=" $NVM_HAS_COLORS " '
17411741function alen(arr, i, len) { len=0; for(i in arr) len++; return len; }
17421742function v2a(v, a, s) { s=v; sub(/^(iojs-)?v/, "", s); split(s, a, "."); }
1743- 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; }
1743+ 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; }
17441744BEGIN {
17451745 fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *";
17461746 fmt_system = has_colors ? (system_color ? "\033[" system_color "%15s\033[0m" : "%15s") : "%15s *";
@@ -1755,14 +1755,11 @@ BEGIN {
17551755 split(remote_versions, lines, "|");
17561756 split(installed_versions, installed, "|");
17571757 rows = alen(lines);
1758- filter = (min_ver != "v0" );
1758+ filter_on = (vcmp("v0.0.0", min_ver) != 0 );
17591759 for (m = n = 1; n <= rows; n++) {
17601760 split(lines[n], fields, "[[:blank:]]+");
17611761 cols = alen(fields);
17621762 version = fields[1];
1763- if (filter && comp(version, min_ver) < 0) continue;
1764-
1765- filter = 0;
17661763 is_installed = 0;
17671764 for (i in installed) {
17681765 if (version == installed[i]) {
@@ -1771,6 +1768,14 @@ BEGIN {
17711768 }
17721769 }
17731770
1771+ if (filter_on && !is_installed) {
1772+ if (vcmp(version, min_ver) >= 0) {
1773+ filter_on = 0;
1774+ } else {
1775+ continue;
1776+ }
1777+ }
1778+
17741779 fmt_version = "%15s";
17751780 if (version == current) {
17761781 fmt_version = fmt_current;
@@ -1792,8 +1797,8 @@ BEGIN {
17921797 output[m++] = formatted;
17931798 }
17941799
1795- for (m in output ) {
1796- print output[m ]
1800+ for (n=1; n < m; n++ ) {
1801+ print output[n ]
17971802 }
17981803
17991804 exit
0 commit comments