diff --git a/nvm.sh b/nvm.sh index 34dde16..acd7f2d 100644 --- a/nvm.sh +++ b/nvm.sh @@ -19,8 +19,12 @@ fi # Auto detect the NVM_DIR if [ ! -d "$NVM_DIR" ]; then - if [ -n "$BASH_SOURCE" ]; then - export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) + if [ -n "${BASH_SOURCE}" ]; then + export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname $BASH_SOURCE) > /dev/null && pwd) + elif [ "$(basename $0)" = nvm.sh ]; then + # Works in shells that put the path of the sourcee into $0. Unfortunately + # dash is not among these. + export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname $0) > /dev/null && pwd) else export NVM_DIR=$HOME/.nvm fi diff --git a/test/fast/$BASH_SOURCE should not be a problem in sh and zsh b/test/fast/$BASH_SOURCE should not be a problem in sh and zsh new file mode 100755 index 0000000..24a7a18 --- /dev/null +++ b/test/fast/$BASH_SOURCE should not be a problem in sh and zsh @@ -0,0 +1,8 @@ +#!/bin/sh + +echo Testing bash +bash -c '. ../../nvm.sh' +echo Testing zsh +zsh -c '. ../../nvm.sh' +echo Testing sh +sh -c '. ../../nvm.sh' diff --git a/test/fast/Sourcing nvm.sh from another path than the default one should not show find errors b/test/fast/Sourcing nvm.sh from another path than the default one should not show find errors new file mode 100755 index 0000000..1498e0c --- /dev/null +++ b/test/fast/Sourcing nvm.sh from another path than the default one should not show find errors @@ -0,0 +1,8 @@ +#!/bin/zsh + +# ~/.nvm must not be present +. ../../nvm.sh + +# Displays +# find: ‘/.nvm/’: No such file or directory +# find: ‘/.nvm/’: No such file or directory