Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 83 additions & 99 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ nvm_set_colors() {
nvm_echo "Setting colors to: ${INSTALLED_COLOR} ${LTS_AND_SYSTEM_COLOR} ${CURRENT_COLOR} ${NOT_INSTALLED_COLOR} ${DEFAULT_COLOR}"
nvm_echo "WARNING: Colors may not display because they are not supported in this shell."
else
nvm_echo_with_colors "Setting colors to: \033[$(nvm_print_color_code "${INSTALLED_COLOR}") ${INSTALLED_COLOR}\033[$(nvm_print_color_code "${LTS_AND_SYSTEM_COLOR}") ${LTS_AND_SYSTEM_COLOR}\033[$(nvm_print_color_code "${CURRENT_COLOR}") ${CURRENT_COLOR}\033[$(nvm_print_color_code "${NOT_INSTALLED_COLOR}") ${NOT_INSTALLED_COLOR}\033[$(nvm_print_color_code "${DEFAULT_COLOR}") ${DEFAULT_COLOR}\033[0m"
nvm_echo_with_colors "Setting colors to: $(nvm_wrap_with_color_code "${INSTALLED_COLOR}" "${INSTALLED_COLOR}")$(nvm_wrap_with_color_code "${LTS_AND_SYSTEM_COLOR}" "${LTS_AND_SYSTEM_COLOR}")$(nvm_wrap_with_color_code "${CURRENT_COLOR}" "${CURRENT_COLOR}")$(nvm_wrap_with_color_code "${NOT_INSTALLED_COLOR}" "${NOT_INSTALLED_COLOR}")$(nvm_wrap_with_color_code "${DEFAULT_COLOR}" "${DEFAULT_COLOR}")"
fi
export NVM_COLORS="$1"
else
Expand All @@ -853,60 +853,73 @@ nvm_set_colors() {
nvm_get_colors() {
local COLOR
local SYS_COLOR
if [ -n "${NVM_COLORS-}" ]; then
case $1 in
1) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 1, 1); }')");;
2) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 2, 1); }')");;
3) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 3, 1); }')");;
4) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 4, 1); }')");;
5) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 5, 1); }')");;
6)
SYS_COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 2, 1); }')")
COLOR=$(nvm_echo "$SYS_COLOR" | command tr '0;' '1;')
;;
*)
nvm_err "Invalid color index, ${1-}"
return 1
local COLORS
COLORS="${NVM_COLORS:-bygre}"
case $1 in
1) COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 1, 1); }')");;
2) COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 2, 1); }')");;
3) COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 3, 1); }')");;
4) COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 4, 1); }')");;
5) COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 5, 1); }')");;
6)
SYS_COLOR=$(nvm_print_color_code "$(echo "$COLORS" | awk '{ print substr($0, 2, 1); }')")
COLOR=$(nvm_echo "$SYS_COLOR" | command tr '0;' '1;')
;;
esac
*)
nvm_err "Invalid color index, ${1-}"
return 1
;;
esac

nvm_echo "$COLOR"
}

nvm_wrap_with_color_code() {
local CODE
CODE="$(nvm_print_color_code "${1}" 2>/dev/null ||:)"
local TEXT
TEXT="${2-}"
if nvm_has_colors && [ -n "${CODE}" ]; then
nvm_echo_with_colors "\033[${CODE}${TEXT}\033[0m"
else
case $1 in
1) COLOR='0;34m';;
2) COLOR='0;33m';;
3) COLOR='0;32m';;
4) COLOR='0;31m';;
5) COLOR='0;37m';;
6) COLOR='1;33m';;
*)
nvm_err "Invalid color index, ${1-}"
return 1
;;
esac
nvm_echo "${TEXT}"
fi
}

echo "$COLOR"
nvm_wrap_with_color_code() {
local CODE
CODE="$(nvm_print_color_code "${1}" 2>/dev/null ||:)"
local TEXT
TEXT="${2-}"
if nvm_has_colors && [ -n "${CODE}" ]; then
nvm_echo_with_colors "\033[${CODE}${TEXT}\033[0m"
else
nvm_echo "${TEXT}"
fi
}

nvm_print_color_code() {
case "${1-}" in
'r') nvm_echo '0;31m';;
'R') nvm_echo '1;31m';;
'g') nvm_echo '0;32m';;
'G') nvm_echo '1;32m';;
'b') nvm_echo '0;34m';;
'B') nvm_echo '1;34m';;
'c') nvm_echo '0;36m';;
'C') nvm_echo '1;36m';;
'm') nvm_echo '0;35m';;
'M') nvm_echo '1;35m';;
'y') nvm_echo '0;33m';;
'Y') nvm_echo '1;33m';;
'k') nvm_echo '0;30m';;
'K') nvm_echo '1;30m';;
'e') nvm_echo '0;37m';;
'W') nvm_echo '1;37m';;
*) nvm_err 'Invalid color code';
return 1
'0') return 0 ;;
'r') nvm_echo '0;31m' ;;
'R') nvm_echo '1;31m' ;;
'g') nvm_echo '0;32m' ;;
'G') nvm_echo '1;32m' ;;
'b') nvm_echo '0;34m' ;;
'B') nvm_echo '1;34m' ;;
'c') nvm_echo '0;36m' ;;
'C') nvm_echo '1;36m' ;;
'm') nvm_echo '0;35m' ;;
'M') nvm_echo '1;35m' ;;
'y') nvm_echo '0;33m' ;;
'Y') nvm_echo '1;33m' ;;
'k') nvm_echo '0;30m' ;;
'K') nvm_echo '1;30m' ;;
'e') nvm_echo '0;37m' ;;
'W') nvm_echo '1;37m' ;;
*)
nvm_err "Invalid color code: ${1-}";
return 1
;;
esac
}
Expand Down Expand Up @@ -1699,15 +1712,15 @@ nvm_print_versions() {
-v current_color="$CURRENT_COLOR" -v default_color="$DEFAULT_COLOR" \
-v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" '
BEGIN {
fmt_installed = has_colors ? ("\033[" installed_color "%15s\033[0m") : "%15s *";
fmt_system = has_colors ? ("\033[" system_color "%15s\033[0m") : "%15s *";
fmt_current = has_colors ? ("\033[" current_color "->%13s\033[0m") : "->%13s *";
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 *";
fmt_current = has_colors ? (current_color ? "\033[" current_color "->%13s\033[0m" : "%15s") : "->%13s *";

latest_lts_color = current_color;
sub(/0;/, "1;", latest_lts_color);

fmt_latest_lts = has_colors ? ("\033[" latest_lts_color " (Latest LTS: %s)\033[0m") : " (Latest LTS: %s)";
fmt_old_lts = has_colors ? ("\033[" old_lts_color " (LTS: %s)\033[0m") : " (LTS: %s)";
fmt_latest_lts = has_colors && latest_lts_color ? ("\033[" latest_lts_color " (Latest LTS: %s)\033[0m") : " (Latest LTS: %s)";
fmt_old_lts = has_colors && old_lts_color ? ("\033[" old_lts_color " (LTS: %s)\033[0m") : " (LTS: %s)";

split(remote_versions, lines, "|");
split(installed_versions, installed, "|");
Expand Down Expand Up @@ -2811,38 +2824,6 @@ nvm() {
fi
done

local INITIAL_COLOR_INFO
local RED_INFO
local GREEN_INFO
local BLUE_INFO
local CYAN_INFO
local MAGENTA_INFO
local YELLOW_INFO
local BLACK_INFO
local GREY_WHITE_INFO

if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
INITIAL_COLOR_INFO='\033[0;34m b\033[0m \033[0;34m y\033[0m \033[0;32m g\033[0m \033[0;31m r\033[0m \033[0;37m e\033[0m'
RED_INFO='\033[0;31m r\033[0m/\033[1;31mR\033[0m = \033[0;31mred\033[0m / \033[1;31mbold red\033[0m'
GREEN_INFO='\033[0;32m g\033[0m/\033[1;32mG\033[0m = \033[0;32mgreen\033[0m / \033[1;32mbold green\033[0m'
BLUE_INFO='\033[0;34m b\033[0m/\033[1;34mB\033[0m = \033[0;34mblue\033[0m / \033[1;34mbold blue\033[0m'
CYAN_INFO='\033[0;36m c\033[0m/\033[1;36mC\033[0m = \033[0;36mcyan\033[0m / \033[1;36mbold cyan\033[0m'
MAGENTA_INFO='\033[0;35m m\033[0m/\033[1;35mM\033[0m = \033[0;35mmagenta\033[0m / \033[1;35mbold magenta\033[0m'
YELLOW_INFO='\033[0;33m y\033[0m/\033[1;33mY\033[0m = \033[0;33myellow\033[0m / \033[1;33mbold yellow\033[0m'
BLACK_INFO='\033[0;30m k\033[0m/\033[1;30mK\033[0m = \033[0;30mblack\033[0m / \033[1;30mbold black\033[0m'
GREY_WHITE_INFO='\033[0;37m e\033[0m/\033[1;37mW\033[0m = \033[0;37mlight grey\033[0m / \033[1;37mwhite\033[0m'
else
INITIAL_COLOR_INFO='bygre'
RED_INFO='r/R = red / bold red'
GREEN_INFO='g/G = green / bold green'
BLUE_INFO='b/B = blue / bold blue'
CYAN_INFO='c/C = cyan / bold cyan'
MAGENTA_INFO='m/M = magenta / bold magenta'
YELLOW_INFO='y/Y = yellow / bold yellow'
BLACK_INFO='k/K = black / bold black'
GREY_WHITE_INFO='e/W = light grey / white'
fi

local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
Expand Down Expand Up @@ -2919,17 +2900,16 @@ nvm() {
nvm_echo ' nvm cache clear Empty cache directory for nvm'
nvm_echo ' nvm set-colors [<color codes>] Set five text colors using format "yMeBg". Available when supported.'
nvm_echo ' Initial colors are:'
nvm_echo_with_colors " ${INITIAL_COLOR_INFO}"
nvm_echo_with_colors " $(nvm_wrap_with_color_code b b)$(nvm_wrap_with_color_code y y)$(nvm_wrap_with_color_code g g)$(nvm_wrap_with_color_code r r)$(nvm_wrap_with_color_code e e)"
nvm_echo ' Color codes:'
nvm_echo_with_colors " ${RED_INFO}"
nvm_echo_with_colors " ${GREEN_INFO}"
nvm_echo_with_colors " ${BLUE_INFO}"
nvm_echo_with_colors " ${CYAN_INFO}"
nvm_echo_with_colors " ${MAGENTA_INFO}"
nvm_echo_with_colors " ${YELLOW_INFO}"
nvm_echo_with_colors " ${BLACK_INFO}"
nvm_echo_with_colors " ${GREY_WHITE_INFO}"
nvm_echo
nvm_echo_with_colors " $(nvm_wrap_with_color_code r r)/$(nvm_wrap_with_color_code R R) = $(nvm_wrap_with_color_code r red) / $(nvm_wrap_with_color_code R 'bold red')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code g g)/$(nvm_wrap_with_color_code G G) = $(nvm_wrap_with_color_code g green) / $(nvm_wrap_with_color_code G 'bold green')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code b b)/$(nvm_wrap_with_color_code B B) = $(nvm_wrap_with_color_code b blue) / $(nvm_wrap_with_color_code B 'bold blue')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code c c)/$(nvm_wrap_with_color_code C C) = $(nvm_wrap_with_color_code c cyan) / $(nvm_wrap_with_color_code C 'bold cyan')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code m m)/$(nvm_wrap_with_color_code M M) = $(nvm_wrap_with_color_code m magenta) / $(nvm_wrap_with_color_code M 'bold magenta')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code y y)/$(nvm_wrap_with_color_code Y Y) = $(nvm_wrap_with_color_code y yellow) / $(nvm_wrap_with_color_code Y 'bold yellow')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code k k)/$(nvm_wrap_with_color_code K K) = $(nvm_wrap_with_color_code k black) / $(nvm_wrap_with_color_code K 'bold black')"
nvm_echo_with_colors " $(nvm_wrap_with_color_code e e)/$(nvm_wrap_with_color_code W W) = $(nvm_wrap_with_color_code e 'light grey') / $(nvm_wrap_with_color_code W white)"
nvm_echo 'Example:'
nvm_echo ' nvm install 8.0.0 Install a specific version number'
nvm_echo ' nvm use 8.0 Use the latest available 8.0.x release'
Expand Down Expand Up @@ -3308,23 +3288,26 @@ nvm() {
fi

local EXIT_CODE
EXIT_CODE=0

if nvm_is_version_installed "${VERSION}"; then
nvm_err "${VERSION} is already installed."
if nvm use "${VERSION}"; then
nvm use "${VERSION}"
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
if [ "${NVM_UPGRADE_NPM}" = 1 ]; then
nvm install-latest-npm
EXIT_CODE=$?
fi
if [ $EXIT_CODE -ne 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
EXIT_CODE=$?
fi
if [ $EXIT_CODE -ne 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
fi

if [ -n "${LTS-}" ]; then
LTS="$(echo "${LTS}" | tr '[:upper:]' '[:lower:]')"
nvm_ensure_default_set "lts/${LTS}"
Expand Down Expand Up @@ -3381,7 +3364,10 @@ nvm() {
if [ $nobinary -ne 1 ] && nvm_binary_available "${VERSION}"; then
NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}" "${nosource}"
EXIT_CODE=$?
else
EXIT_CODE=-1
fi

if [ $EXIT_CODE -ne 0 ]; then
if [ -z "${NVM_MAKE_JOBS-}" ]; then
nvm_get_make_jobs
Expand All @@ -3395,7 +3381,6 @@ nvm() {
EXIT_CODE=$?
fi
fi

fi

if [ $EXIT_CODE -eq 0 ] && nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then
Expand All @@ -3410,7 +3395,6 @@ nvm() {
fi
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
EXIT_CODE=$?
fi
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
Expand Down Expand Up @@ -4219,7 +4203,7 @@ nvm() {
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
nvm_npmrc_bad_news_bears \
nvm_get_colors nvm_set_colors nvm_print_color_code nvm_format_help_message_colors \
nvm_get_colors nvm_set_colors nvm_print_color_code nvm_wrap_with_color_code nvm_format_help_message_colors \
nvm_echo_with_colors nvm_err_with_colors \
nvm_get_artifact_compression nvm_install_binary_extract nvm_extract_tarball \
>/dev/null 2>&1
Expand Down
1 change: 1 addition & 0 deletions test/fast/Unit tests/mocks/nodejs.org-dist-index.tab
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version date files npm v8 uv zlib openssl modules lts security
v18.11.0 2022-10-13 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.2.154.15 1.43.0 1.2.11 3.0.5+quic 108 - -
v18.10.0 2022-09-28 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.2.154.15 1.43.0 1.2.11 3.0.5+quic 108 - -
v18.9.1 2022-09-23 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.1 10.2.154.15 1.43.0 1.2.11 3.0.5+quic 108 - true
v18.9.0 2022-09-07 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.1 10.2.154.15 1.43.0 1.2.11 3.0.5+quic 108 - -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version date files npm v8 uv zlib openssl modules lts security
v19.0.0-nightly202210156fb466bc38 2022-10-15 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.7.193.13 1.43.0 1.2.11 3.0.5+quic 111 - -
v19.0.0-nightly2022101437e5152245 2022-10-14 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.7.193.13 1.43.0 1.2.11 3.0.5+quic 111 - -
v19.0.0-nightly20221013214354fc9f 2022-10-13 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.7.193.13 1.43.0 1.2.11 3.0.5+quic 111 - -
v19.0.0-nightly2022101219a909902a 2022-10-12 aix-ppc64,headers,linux-arm64,linux-armv7l,linux-ppc64le,linux-s390x,linux-x64,osx-arm64-tar,osx-x64-pkg,osx-x64-tar,src,win-x64-7z,win-x64-exe,win-x64-msi,win-x64-zip,win-x86-7z,win-x86-exe,win-x86-msi,win-x86-zip 8.19.2 10.7.193.13 1.43.0 1.2.11 3.0.5+quic 111 - -
v19.0.0-nightly2022101136805e8524 2022-10-11 aix-ppc64 8.19.2 10.7.193.13 1.43.0 1.2.11 3.0.5+quic 111 - -
Expand Down
14 changes: 7 additions & 7 deletions test/fast/Unit tests/mocks/nvm ls-remote iojs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
iojs-v1.0.1
iojs-v1.0.2
iojs-v1.0.3
 iojs-v1.0.4
iojs-v1.0.4
iojs-v1.1.0
iojs-v1.2.0
iojs-v1.3.0
Expand All @@ -20,7 +20,7 @@
iojs-v1.8.1
iojs-v1.8.2
iojs-v1.8.3
 iojs-v1.8.4
iojs-v1.8.4
iojs-v2.0.0
iojs-v2.0.1
iojs-v2.0.2
Expand All @@ -33,9 +33,9 @@
iojs-v2.3.3
iojs-v2.3.4
iojs-v2.4.0
 iojs-v2.5.0
 iojs-v3.0.0
 iojs-v3.1.0
 iojs-v3.2.0
iojs-v2.5.0
iojs-v3.0.0
iojs-v3.1.0
iojs-v3.2.0
iojs-v3.3.0
 iojs-v3.3.1
iojs-v3.3.1
Loading