From 9854928ba9ff6f24360207fa90135574746838f5 Mon Sep 17 00:00:00 2001 From: Spike Grobstein Date: Thu, 3 May 2018 08:22:07 -0700 Subject: [PATCH] [New] `install.sh`: allow user to explicitly opt out of nvm adding the source string this is done by checking if the user supplies `PROFILE=/dev/null` when running `install.sh`, the `nvm_detect_profile` function will not output any strings, causing `nvm_do_install` to skip adding `SOURCE_STR`. --- install.sh | 5 +++++ test/install_script/nvm_detect_profile | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/install.sh b/install.sh index 77f7f31..7bf62df 100755 --- a/install.sh +++ b/install.sh @@ -212,6 +212,11 @@ nvm_try_profile() { # Otherwise, an empty string is returned # nvm_detect_profile() { + if [ "${PROFILE-}" = '/dev/null' ]; then + # the user has specifically requested NOT to have nvm touch their profile + return + fi + if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then echo "${PROFILE}" return diff --git a/test/install_script/nvm_detect_profile b/test/install_script/nvm_detect_profile index 1044659..54815ec 100755 --- a/test/install_script/nvm_detect_profile +++ b/test/install_script/nvm_detect_profile @@ -28,6 +28,12 @@ setup # Confirm profile detection via $SHELL works and that $PROFILE overrides profile detection # +# setting $PROFILE to /dev/null should return no detected profile +NVM_DETECT_PROFILE="$(PROFILE='/dev/null'; nvm_detect_profile)" +if [ -n "$NVM_DETECT_PROFILE" ]; then + die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null" +fi + # .bashrc should be detected for bash NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)" if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then