Compare commits

..

1 Commits

Author SHA1 Message Date
Steven Dee (Jōshin)
f3d3794720
Merge c1064550872bfc16afe02ec6edeb73ff3847a3da into f439acda4af4d22c985d02e75f8bddac1479869b 2024-07-26 16:38:05 -07:00
2 changed files with 34 additions and 20 deletions

52
nvm.sh
View File

@ -83,7 +83,7 @@ nvm_has_colors() {
if nvm_has tput; then if nvm_has tput; then
NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)" NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
fi fi
[ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ] [ "${NVM_NUM_COLORS:--1}" -ge 8 ]
} }
nvm_curl_libz_support() { nvm_curl_libz_support() {
@ -1094,7 +1094,7 @@ nvm_print_formatted_alias() {
fi fi
local ARROW local ARROW
ARROW='->' ARROW='->'
if nvm_has_colors; then if [ -z "${NVM_NO_COLORS}" ] && nvm_has_colors; then
ARROW='\033[0;90m->\033[0m' ARROW='\033[0;90m->\033[0m'
if [ "_${DEFAULT}" = '_true' ]; then if [ "_${DEFAULT}" = '_true' ]; then
NEWLINE=" \033[${DEFAULT_COLOR}(default)\033[0m\n" NEWLINE=" \033[${DEFAULT_COLOR}(default)\033[0m\n"
@ -1832,7 +1832,7 @@ nvm_print_versions() {
DEFAULT_COLOR=$(nvm_get_colors 5) DEFAULT_COLOR=$(nvm_get_colors 5)
LTS_COLOR=$(nvm_get_colors 6) LTS_COLOR=$(nvm_get_colors 6)
if nvm_has_colors; then if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
NVM_HAS_COLORS=1 NVM_HAS_COLORS=1
fi fi
@ -4436,23 +4436,37 @@ nvm() {
} }
nvm_get_default_packages() { nvm_get_default_packages() {
local NVM_DEFAULT_PACKAGE_FILE local NVM_DEFAULT_PACKAGE_FILE="${NVM_DIR}/default-packages"
NVM_DEFAULT_PACKAGE_FILE="${NVM_DIR}/default-packages"
if [ -f "${NVM_DEFAULT_PACKAGE_FILE}" ]; then if [ -f "${NVM_DEFAULT_PACKAGE_FILE}" ]; then
command awk -v filename="${NVM_DEFAULT_PACKAGE_FILE}" ' local DEFAULT_PACKAGES
/^[[:space:]]*#/ { next } # Skip lines that begin with # DEFAULT_PACKAGES=''
/^[[:space:]]*$/ { next } # Skip empty lines
/[[:space:]]/ && !/^[[:space:]]*#/ { # Read lines from $NVM_DIR/default-packages
print "Only one package per line is allowed in `" filename "`. Please remove any lines with multiple space-separated values." > "/dev/stderr" local line
err = 1 # ensure a trailing newline
exit 1 WORK=$(mktemp -d) || exit $?
} # shellcheck disable=SC2064
{ trap "command rm -rf '$WORK'" EXIT
if (NR > 1 && !prev_space) printf " " # shellcheck disable=SC1003
printf "%s", $0 sed -e '$a\' "${NVM_DEFAULT_PACKAGE_FILE}" > "${WORK}/default-packages"
prev_space = 0 while IFS=' ' read -r line; do
} # Skip empty lines.
' "${NVM_DEFAULT_PACKAGE_FILE}" [ -n "${line-}" ] || continue
# Skip comment lines that begin with `#`.
[ "$(nvm_echo "${line}" | command cut -c1)" != "#" ] || continue
# Fail on lines that have multiple space-separated words
case $line in
*\ *)
nvm_err "Only one package per line is allowed in the ${NVM_DIR}/default-packages file. Please remove any lines with multiple space-separated values."
return 1
;;
esac
DEFAULT_PACKAGES="${DEFAULT_PACKAGES}${line} "
done < "${WORK}/default-packages"
echo "${DEFAULT_PACKAGES}" | command xargs
fi fi
} }

View File

@ -74,7 +74,7 @@ rimraf
EOF EOF
DEFAULT_PKGS="$(nvm_get_default_packages 2>&1 >/dev/null)" DEFAULT_PKGS="$(nvm_get_default_packages 2>&1 >/dev/null)"
EXPECTED_PKGS="Only one package per line is allowed in \`${FILE}\`. Please remove any lines with multiple space-separated values." EXPECTED_PKGS="Only one package per line is allowed in the $FILE file. Please remove any lines with multiple space-separated values."
[ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "4: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<" [ "${DEFAULT_PKGS}" = "${EXPECTED_PKGS}" ] || die "4: expected default packages >${EXPECTED_PKGS}<; got >${DEFAULT_PKGS}<"
cleanup cleanup