@@ -4436,37 +4436,23 @@ nvm() {
4436
4436
}
4437
4437
4438
4438
nvm_get_default_packages () {
4439
- local NVM_DEFAULT_PACKAGE_FILE=" ${NVM_DIR} /default-packages"
4439
+ local NVM_DEFAULT_PACKAGE_FILE
4440
+ NVM_DEFAULT_PACKAGE_FILE=" ${NVM_DIR} /default-packages"
4440
4441
if [ -f " ${NVM_DEFAULT_PACKAGE_FILE} " ]; then
4441
- local DEFAULT_PACKAGES
4442
- DEFAULT_PACKAGES=' '
4443
-
4444
- # Read lines from $NVM_DIR/default-packages
4445
- local line
4446
- # ensure a trailing newline
4447
- WORK=$( mktemp -d) || exit $?
4448
- # shellcheck disable=SC2064
4449
- trap " command rm -rf '$WORK '" EXIT
4450
- # shellcheck disable=SC1003
4451
- sed -e ' $a\' " ${NVM_DEFAULT_PACKAGE_FILE} " > " ${WORK} /default-packages"
4452
- while IFS=' ' read -r line; do
4453
- # Skip empty lines.
4454
- [ -n " ${line-} " ] || continue
4455
-
4456
- # Skip comment lines that begin with `#`.
4457
- [ " $( nvm_echo " ${line} " | command cut -c1) " != " #" ] || continue
4458
-
4459
- # Fail on lines that have multiple space-separated words
4460
- case $line in
4461
- * \ * )
4462
- 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."
4463
- return 1
4464
- ;;
4465
- esac
4466
-
4467
- DEFAULT_PACKAGES=" ${DEFAULT_PACKAGES}${line} "
4468
- done < " ${WORK} /default-packages"
4469
- echo " ${DEFAULT_PACKAGES} " | command xargs
4442
+ command awk -v filename=" ${NVM_DEFAULT_PACKAGE_FILE} " '
4443
+ /^[[:space:]]*#/ { next } # Skip lines that begin with #
4444
+ /^[[:space:]]*$/ { next } # Skip empty lines
4445
+ /[[:space:]]/ && !/^[[:space:]]*#/ {
4446
+ print "Only one package per line is allowed in `" filename "`. Please remove any lines with multiple space-separated values." > "/dev/stderr"
4447
+ err = 1
4448
+ exit 1
4449
+ }
4450
+ {
4451
+ if (NR > 1 && !prev_space) printf " "
4452
+ printf "%s", $0
4453
+ prev_space = 0
4454
+ }
4455
+ ' " ${NVM_DEFAULT_PACKAGE_FILE} "
4470
4456
fi
4471
4457
}
4472
4458
0 commit comments