From af276b80fe83e081512a047bdcb99aa666ff1fdc Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 29 Dec 2016 01:53:53 -0800 Subject: [PATCH 1/2] try to use realpath to find nvm's dir --- nvm-exec | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nvm-exec b/nvm-exec index c47cd06..beabd57 100755 --- a/nvm-exec +++ b/nvm-exec @@ -1,6 +1,14 @@ #!/usr/bin/env bash -DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +function find_nvm_dir() { + if which realpath >& /dev/null; then + dirname "$(realpath "$0")" + else + command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd + fi +} + +DIR="$(find_nvm_dir)" # shellcheck disable=SC1090 \. "$DIR/nvm.sh" --no-use From d4f6c201cb60688242e8bc1cb14d34a20413e670 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 29 Dec 2016 02:04:49 -0800 Subject: [PATCH 2/2] ensure nvm.sh really exist at the directory determined --- nvm-exec | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nvm-exec b/nvm-exec index beabd57..b246b61 100755 --- a/nvm-exec +++ b/nvm-exec @@ -1,7 +1,15 @@ #!/usr/bin/env bash +function nvm_fail() { + echo "$1" >&2 + exit 127 +} + +has_realpath="" + function find_nvm_dir() { if which realpath >& /dev/null; then + has_realpath=yes dirname "$(realpath "$0")" else command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd @@ -10,6 +18,16 @@ function find_nvm_dir() { DIR="$(find_nvm_dir)" +function check_nvm_sh() { + if [ ! -f "$DIR/nvm.sh" ]; then + local rp_msg="" + [ "$has_realpath" == "yes" ] || rp_msg="; missing realpath command for finding nvm-exec's realpath to search for nvm.sh" + nvm_fail "Unable to find nvm.sh at $DIR$rp_msg" + fi +} + +check_nvm_sh + # shellcheck disable=SC1090 \. "$DIR/nvm.sh" --no-use