diff --git a/nvm.sh b/nvm.sh index 2cf767d251..0837a2c01d 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1663,7 +1663,8 @@ nvm_print_versions() { NVM_HAS_COLORS=1 fi - awk -v _input="${1-}" -v _nvm_ls="$(nvm_ls)" -v current="$NVM_CURRENT" \ + command awk -v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" \ + -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="$LTS_COLOR" -v has_colors="$NVM_HAS_COLORS" ' @@ -1679,14 +1680,13 @@ BEGIN { fmt_aux[1] = " "; fmt_aux[2] = " * "; - split(_input, lines, "\n"); - split(_nvm_ls, installed, "\n"); - total = length(lines); + split(remote_versions, lines, "|"); + split(installed_versions, installed, "|"); + rows = length(lines); - for (n = 1; n <= total; n++) { - split(lines[n], fields, /\s+/); - - len = length(fields); + for (n = 1; n <= rows; n++) { + split(lines[n], fields, "[[:blank:]]+"); + cols = length(fields); version = fields[1]; is_installed = 0; @@ -1707,18 +1707,18 @@ BEGIN { } aux = (!has_colors && is_installed) + 1; - if (len == 1) { + if (cols == 1) { formatted = sprintf(fmt_version, version); - } else if (len == 2) { + } else if (cols == 2) { formatted = sprintf((fmt_version fmt_aux[aux] fmt_old_lts), version, fields[2]); - } else if (len == 3 && fields[3] == "*") { + } else if (cols == 3 && fields[3] == "*") { formatted = sprintf((fmt_version fmt_aux[aux] fmt_latest_lts), version, fields[2]); } output[n] = formatted; } - for (n = 1; n <= total; n++) { + for (n = 1; n <= rows; n++) { print output[n] }