[Fix] `nvm ls-remote`: properly label latest LTS versions instead of just the latest one in the filter

Fixes #2166
diff --git a/nvm.sh b/nvm.sh
index 7e2fbeb..8bb36f7 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -549,7 +549,8 @@
   NVM_LS_REMOTE_POST_MERGED_OUTPUT=''
   if [ -z "${NVM_FLAVOR-}" ] || [ "${NVM_FLAVOR-}" = "${NVM_NODE_PREFIX}" ]; then
     local NVM_LS_REMOTE_OUTPUT
-    NVM_LS_REMOTE_OUTPUT=$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "${PATTERN-}") &&:
+    # extra space is needed here to avoid weird behavior when `nvm_ls_remote` ends in a `*`
+    NVM_LS_REMOTE_OUTPUT="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "${PATTERN-}") " &&:
     NVM_LS_REMOTE_EXIT_CODE=$?
     # split output into two
     NVM_LS_REMOTE_PRE_MERGED_OUTPUT="${NVM_LS_REMOTE_OUTPUT%%v4\.0\.0*}"
@@ -567,15 +568,17 @@
     NVM_LS_REMOTE_IOJS_EXIT_CODE=$?
   fi
 
+  # the `sed` removes both blank lines, and only-whitespace lines (see "weird behavior" ~19 lines up)
   VERSIONS="$(nvm_echo "${NVM_LS_REMOTE_PRE_MERGED_OUTPUT}
 ${NVM_LS_REMOTE_IOJS_OUTPUT}
-${NVM_LS_REMOTE_POST_MERGED_OUTPUT}" | nvm_grep -v "N/A" | command sed '/^$/d')"
+${NVM_LS_REMOTE_POST_MERGED_OUTPUT}" | nvm_grep -v "N/A" | command sed '/^ *$/d')"
 
   if [ -z "${VERSIONS}" ]; then
     nvm_echo 'N/A'
     return 3
   fi
-  nvm_echo "${VERSIONS}"
+  # the `sed` is to remove trailing whitespaces (see "weird behavior" ~25 lines up)
+  nvm_echo "${VERSIONS}" | command sed 's/ *$//g'
   return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE
 }
 
@@ -1196,7 +1199,7 @@
   PATTERN="${3-}"
 
   local VERSIONS
-  if [ -n "${PATTERN}" ]; then
+  if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
     if [ "${FLAVOR}" = 'iojs' ]; then
       PATTERN="$(nvm_ensure_version_prefix "$(nvm_strip_iojs_prefix "${PATTERN}")")"
     else
@@ -1239,12 +1242,20 @@
       nvm_make_alias "${LTS_ALIAS}" "${LTS_VERSION}" >/dev/null 2>&1
     done
 
-  VERSIONS="$({ command awk -v pattern="${PATTERN-}" -v lts="${LTS-}" '{
+  VERSIONS="$({ command awk -v lts="${LTS-}" '{
         if (!$1) { next }
-        if (pattern && tolower($1) !~ tolower(pattern)) { next }
-        if (lts == "*" && $10 ~ /^\-?$/) { next }
+        if (lts && $10 ~ /^\-?$/) { next }
         if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }
-        if ($10 !~ /^\-?$/) print $1, $10; else print $1
+        if ($10 !~ /^\-?$/) {
+          if ($10 && $10 != prev) {
+            print $1, $10, "*"
+          } else {
+            print $1, $10
+          }
+        } else {
+          print $1
+        }
+        prev=$10;
       }' \
     | nvm_grep -w "${PATTERN:-.*}" \
     | $SORT_COMMAND; } << EOF
@@ -1441,7 +1452,7 @@
   local LTS_FORMAT
   nvm_echo "${1-}" \
   | command sed '1!G;h;$!d' \
-  | command awk '{ if ($2 && a[$2]++) { print $1, "(LTS: " $2 ")" } else if ($2) { print $1, "(Latest LTS: " $2 ")" } else { print $0 } }' \
+  | command awk '{ if ($2 && $3 && $3 == "*") { print $1, "(Latest LTS: " $2 ")" } else if ($2) { print $1, "(LTS: " $2 ")" } else { print $1 } }' \
   | command sed '1!G;h;$!d' \
   | while read -r VERSION_LINE; do
     VERSION="${VERSION_LINE%% *}"
diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt
index e20669e..78d685d 100644
--- a/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt
+++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt
@@ -33,4 +33,4 @@
 v4.8.6 Argon
 v4.8.7 Argon
 v4.9.0 Argon
-v4.9.1 Argon
+v4.9.1 Argon *
diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly.txt
index ba783b6..bf60759 100644
--- a/test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly.txt
+++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS nightly.txt
@@ -8,8 +8,8 @@
 v6.10.2-nightly20170322426968ddd8 Boron
 v6.10.3-nightly2017040479546c0b5a Boron
 v6.10.4-nightly20170502312091a196 Boron
-v6.11.1-nightly20170607f7ca483d68 Boron
-v8.9.1-nightly20171104a815e1b6a2 Carbon
+v6.11.1-nightly20170607f7ca483d68 Boron *
+v8.9.1-nightly20171104a815e1b6a2 Carbon *
 v10.13.1-nightly20181127a66d8774ac Dubnium
 v10.14.1-nightly20181129bda1cc703a Dubnium
 v10.14.2-nightly20181206fb99a4e9fa Dubnium
@@ -21,5 +21,5 @@
 v10.16.1-nightly201907310339fba1bb Dubnium
 v10.16.2-nightly20190801f025f8524b Dubnium
 v10.16.3-nightly20190807b743000a96 Dubnium
-v10.16.4-nightly20190923859d47593e9fd97e6a9eae6eeb8b6e910acfe434 Dubnium
-v12.13.1-nightly20191022d9174b4cc5 Erbium
+v10.16.4-nightly20190923859d47593e9fd97e6a9eae6eeb8b6e910acfe434 Dubnium *
+v12.13.1-nightly20191022d9174b4cc5 Erbium *
diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt
index ae410d1..8250fac 100644
--- a/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt
+++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt
@@ -33,7 +33,7 @@
 v4.8.6 Argon
 v4.8.7 Argon
 v4.9.0 Argon
-v4.9.1 Argon
+v4.9.1 Argon *
 v6.9.0 Boron
 v6.9.1 Boron
 v6.9.2 Boron
@@ -65,7 +65,7 @@
 v6.15.1 Boron
 v6.16.0 Boron
 v6.17.0 Boron
-v6.17.1 Boron
+v6.17.1 Boron *
 v8.9.0 Carbon
 v8.9.1 Carbon
 v8.9.2 Carbon
@@ -86,7 +86,7 @@
 v8.16.0 Carbon
 v8.16.1 Carbon
 v8.16.2 Carbon
-v8.17.0 Carbon
+v8.17.0 Carbon *
 v10.13.0 Dubnium
 v10.14.0 Dubnium
 v10.14.1 Dubnium
@@ -102,11 +102,11 @@
 v10.17.0 Dubnium
 v10.18.0 Dubnium
 v10.18.1 Dubnium
-v10.19.0 Dubnium
+v10.19.0 Dubnium *
 v12.13.0 Erbium
 v12.13.1 Erbium
 v12.14.0 Erbium
 v12.14.1 Erbium
 v12.15.0 Erbium
 v12.16.0 Erbium
-v12.16.1 Erbium
+v12.16.1 Erbium *
diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote nightly.txt b/test/fast/Unit tests/mocks/nvm_ls_remote nightly.txt
index d6fc63c..9a823a1 100644
--- a/test/fast/Unit tests/mocks/nvm_ls_remote nightly.txt
+++ b/test/fast/Unit tests/mocks/nvm_ls_remote nightly.txt
@@ -35,7 +35,7 @@
 v6.10.2-nightly20170322426968ddd8 Boron
 v6.10.3-nightly2017040479546c0b5a Boron
 v6.10.4-nightly20170502312091a196 Boron
-v6.11.1-nightly20170607f7ca483d68 Boron
+v6.11.1-nightly20170607f7ca483d68 Boron *
 v7.0.0-nightly201610246bbdd668bd
 v7.0.1-nightly2016102527e1749dcb
 v7.1.1-nightly201611093daf11635d
@@ -69,7 +69,7 @@
 v8.7.1-nightly2017102478a6ef46a9
 v8.8.1-nightly201710256fbef7f350
 v8.8.2-nightly20171030f00ba6b142
-v8.9.1-nightly20171104a815e1b6a2 Carbon
+v8.9.1-nightly20171104a815e1b6a2 Carbon *
 v9.0.0-nightly2017103182790d84f2
 v9.0.1-nightly20171105ed0fbd8d72
 v9.1.1-nightly20171207c81e9682c4
@@ -115,7 +115,7 @@
 v10.16.1-nightly201907310339fba1bb Dubnium
 v10.16.2-nightly20190801f025f8524b Dubnium
 v10.16.3-nightly20190807b743000a96 Dubnium
-v10.16.4-nightly20190923859d47593e9fd97e6a9eae6eeb8b6e910acfe434 Dubnium
+v10.16.4-nightly20190923859d47593e9fd97e6a9eae6eeb8b6e910acfe434 Dubnium *
 v11.0.0-nightly20181023d901d16b39
 v11.1.0-nightly20181101af6d26281f
 v12.0.0-nightly20190423859421188b
@@ -123,7 +123,7 @@
 v12.11.1-nightly20190926acd08fdce5
 v12.11.2-nightly201910115fdf4a474f
 v12.12.1-nightly201910123f3c41cfb0
-v12.13.1-nightly20191022d9174b4cc5 Erbium
+v12.13.1-nightly20191022d9174b4cc5 Erbium *
 v13.0.0-nightly2019102271b342f937
 v13.0.2-nightly20191028e4ab6fced1
 v13.1.1-nightly201911219b71534d23
diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote.txt b/test/fast/Unit tests/mocks/nvm_ls_remote.txt
index e6bde79..81a90ff 100644
--- a/test/fast/Unit tests/mocks/nvm_ls_remote.txt
+++ b/test/fast/Unit tests/mocks/nvm_ls_remote.txt
@@ -274,7 +274,7 @@
 v4.8.6 Argon
 v4.8.7 Argon
 v4.9.0 Argon
-v4.9.1 Argon
+v4.9.1 Argon *
 v5.0.0
 v5.1.0
 v5.1.1
@@ -338,7 +338,7 @@
 v6.15.1 Boron
 v6.16.0 Boron
 v6.17.0 Boron
-v6.17.1 Boron
+v6.17.1 Boron *
 v7.0.0
 v7.1.0
 v7.2.0
@@ -391,7 +391,7 @@
 v8.16.0 Carbon
 v8.16.1 Carbon
 v8.16.2 Carbon
-v8.17.0 Carbon
+v8.17.0 Carbon *
 v9.0.0
 v9.1.0
 v9.2.0
@@ -440,7 +440,7 @@
 v10.17.0 Dubnium
 v10.18.0 Dubnium
 v10.18.1 Dubnium
-v10.19.0 Dubnium
+v10.19.0 Dubnium *
 v11.0.0
 v11.1.0
 v11.2.0
@@ -481,7 +481,7 @@
 v12.14.1 Erbium
 v12.15.0 Erbium
 v12.16.0 Erbium
-v12.16.1 Erbium
+v12.16.1 Erbium *
 v13.0.0
 v13.0.1
 v13.1.0