Merge pull request #1734 from PeterDaveHello/improve-NVM_DIR-handling
[Fix] Remove $NVM_DIR trailing slash automatically
commit
c983fefbae
9
nvm.sh
9
nvm.sh
|
@ -257,6 +257,15 @@ if [ -z "${NVM_DIR-}" ]; then
|
||||||
# shellcheck disable=SC1001
|
# shellcheck disable=SC1001
|
||||||
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)"
|
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)"
|
||||||
export NVM_DIR
|
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
|
fi
|
||||||
unset NVM_SCRIPT_SOURCE 2> /dev/null
|
unset NVM_SCRIPT_SOURCE 2> /dev/null
|
||||||
|
|
||||||
|
|
|
@ -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"'
|
Loading…
Reference in New Issue