From 9a4e9060d840b6897a5010de33292045b2b31068 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 26 Dec 2014 12:19:55 -0800 Subject: [PATCH] Don't bother testing --install option on source, or supporting it, unless the shell supports passing options upon sourcing. --- nvm.sh | 8 ++++++-- ...ing nvm.sh with --install and .nvmrc should install it | 8 ++++++++ ...rcing nvm.sh with --install should install the default | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 5a732ce..f907a86 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1102,7 +1102,7 @@ nvm() { echo "0.21.0" ;; "unload" ) - unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to > /dev/null 2>&1 + unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to nvm_supports_source_options > /dev/null 2>&1 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1 ;; * ) @@ -1111,7 +1111,11 @@ nvm() { esac } -if [ "_$1" = "_--install" ]; then +nvm_supports_source_options() { + [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ] +} + +if nvm_supports_source_options && [ "_$1" = "_--install" ]; then VERSION="$(nvm_alias default 2>/dev/null)" if [ -n "$VERSION" ]; then nvm install "$VERSION" >/dev/null diff --git a/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it b/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it index 74316a0..edc5614 100755 --- a/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it +++ b/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it @@ -1,6 +1,14 @@ #!/bin/sh die () { echo $@ ; exit 1; } +supports_source_options () { + [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ] +} + +if ! supports_source_options; then + echo 'this shell does not support passing options on sourcing' + exit 0; +fi echo '0.10.2' > ../../.nvmrc || die 'creation of .nvmrc failed' diff --git a/test/sourcing/Sourcing nvm.sh with --install should install the default b/test/sourcing/Sourcing nvm.sh with --install should install the default index 0b2d631..e25ddf0 100755 --- a/test/sourcing/Sourcing nvm.sh with --install should install the default +++ b/test/sourcing/Sourcing nvm.sh with --install should install the default @@ -1,6 +1,14 @@ #!/bin/sh die () { echo $@ ; exit 1; } +supports_source_options () { + [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ] +} + +if ! supports_source_options; then + echo 'this shell does not support passing options on sourcing' + exit 0; +fi echo '0.10.2' > ../../alias/default || die 'creation of default alias failed'