Merge pull request #1734 from PeterDaveHello/improve-NVM_DIR-handling

[Fix] Remove $NVM_DIR trailing slash automatically
Jordan Harband 2018-04-24 16:22:42 -07:00 committed by GitHub
commit c983fefbae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

9
nvm.sh
View File

@ -257,6 +257,15 @@ if [ -z "${NVM_DIR-}" ]; then
# shellcheck disable=SC1001
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)"
export NVM_DIR
else
# https://unix.stackexchange.com/a/198289
case $NVM_DIR in
*[!/]*/)
NVM_DIR="${NVM_DIR%"${NVM_DIR##*[!/]}"}"
export NVM_DIR
nvm_err "Warning: \$NVM_DIR should not have trailing slashes"
;;
esac
fi
unset NVM_SCRIPT_SOURCE 2> /dev/null

View File

@ -0,0 +1,18 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
export NVM_DIR_BASE="/tmp"
export NVM_DIR="${NVM_DIR_BASE}/"
\. ../../nvm.sh
[ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove the last trailing slash in "$NVM_DIR"'
export NVM_DIR="${NVM_DIR_BASE}//"
\. ../../nvm.sh
[ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove all the last trailing slashes in "$NVM_DIR"'