Print the LTS version on all versions with that info, but put the non-latest in gray.

Jordan Harband 2016-04-24 10:55:30 -07:00
parent ae07c3c345
commit 584bdd8ba3
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 31 additions and 15 deletions

46
nvm.sh
View File

@ -993,36 +993,52 @@ nvm_print_versions() {
fi fi
local LTS_LENGTH local LTS_LENGTH
local LTS_FORMAT local LTS_FORMAT
nvm_echo "$1" | while read -r VERSION_LINE; do nvm_echo "$1" \
VERSION="${VERSION_LINE% *}" | 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 sed '1!G;h;$!d' \
| while read -r VERSION_LINE; do
VERSION="${VERSION_LINE%% *}"
LTS="${VERSION_LINE#* }" LTS="${VERSION_LINE#* }"
FORMAT='%15s' FORMAT='%15s '
if [ "_$VERSION" = "_$NVM_CURRENT" ]; then if [ "_$VERSION" = "_$NVM_CURRENT" ]; then
if [ "${NVM_HAS_COLORS-}" = '1' ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then
FORMAT='\033[0;32m-> %12s\033[0m' FORMAT='\033[0;32m-> %12s\033[0m '
else else
FORMAT='-> %12s *' FORMAT='-> %12s *'
fi fi
elif [ "$VERSION" = "system" ]; then elif [ "$VERSION" = "system" ]; then
if [ "${NVM_HAS_COLORS-}" = '1' ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then
FORMAT='\033[0;33m%15s\033[0m' FORMAT='\033[0;33m%15s\033[0m '
fi fi
elif nvm_is_version_installed "$VERSION"; then elif nvm_is_version_installed "$VERSION"; then
if [ "${NVM_HAS_COLORS-}" = '1' ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then
FORMAT='\033[0;34m%15s\033[0m' FORMAT='\033[0;34m%15s\033[0m '
else else
FORMAT='%15s *' FORMAT='%15s *'
fi fi
fi fi
if [ "$LTS" != "$VERSION" ]; then if [ "${LTS}" != "${VERSION}" ]; then
LTS=" (LTS: $LTS)" case "${LTS}" in
LTS_LENGTH="${#LTS}" *Latest*)
if [ "${NVM_HAS_COLORS-}" = '1' ]; then LTS="${LTS##Latest }"
LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m" LTS_LENGTH="${#LTS}"
else if [ "${NVM_HAS_COLORS-}" = '1' ]; then
LTS_FORMAT="%${LTS_LENGTH}s" LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m"
fi else
command printf -- "${FORMAT}${LTS_FORMAT}\n" "$VERSION" "$LTS" LTS_FORMAT="%${LTS_LENGTH}s"
fi
;;
*)
LTS_LENGTH="${#LTS}"
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
LTS_FORMAT="\033[0;37m%${LTS_LENGTH}s\033[0m"
else
LTS_FORMAT="%${LTS_LENGTH}s"
fi
;;
esac
command printf -- "${FORMAT}${LTS_FORMAT}\n" "$VERSION" " $LTS"
else else
command printf -- "${FORMAT}\n" "$VERSION" command printf -- "${FORMAT}\n" "$VERSION"
fi fi