diff --git a/nvm.sh b/nvm.sh index 969af37..5f02501 100644 --- a/nvm.sh +++ b/nvm.sh @@ -531,22 +531,22 @@ nvm() { echo "Node Version Manager" echo echo "Usage:" - echo " nvm help Show this message" - echo " nvm --version Print out the latest released version of nvm" - echo " nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available" - echo " nvm uninstall Uninstall a version" - echo " nvm use Modify PATH to use . Uses .nvmrc if available" - echo " nvm run [] Run with as arguments. Uses .nvmrc if available for " - echo " nvm current Display currently activated version" - echo " nvm ls List installed versions" - echo " nvm ls List versions matching a given description" - echo " nvm ls-remote List remote versions available for install" - echo " nvm deactivate Undo effects of NVM on current shell" - echo " nvm alias [] Show all aliases beginning with " - echo " nvm alias Set an alias named pointing to " - echo " nvm unalias Deletes the alias named " - echo " nvm copy-packages Install global NPM packages contained in to current version" - echo " nvm unload Unload NVM from shell" + echo " nvm help Show this message" + echo " nvm --version Print out the latest released version of nvm" + echo " nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available" + echo " nvm uninstall Uninstall a version" + echo " nvm [--print-paths] use Modify PATH (and optionally print it) to use . Uses .nvmrc if available" + echo " nvm run [] Run with as arguments. Uses .nvmrc if available for " + echo " nvm current Display currently activated version" + echo " nvm ls List installed versions" + echo " nvm ls List versions matching a given description" + echo " nvm ls-remote List remote versions available for install" + echo " nvm deactivate Undo effects of NVM on current shell" + echo " nvm alias [] Show all aliases beginning with " + echo " nvm alias Set an alias named pointing to " + echo " nvm unalias Deletes the alias named " + echo " nvm copy-packages Install global NPM packages contained in to current version" + echo " nvm unload Unload NVM from shell" echo echo "Example:" echo " nvm install v0.10.24 Install a specific version number" @@ -794,20 +794,35 @@ nvm() { fi ;; "use" ) + shift # start treating the args given to "use" + if [ $# -eq 0 ]; then - nvm help - return 127 - fi - if [ $# -eq 1 ]; then nvm_rc_version if [ -n "$NVM_RC_VERSION" ]; then VERSION=`nvm_version $NVM_RC_VERSION` fi - elif [ "_$2" != '_system' ]; then - VERSION="$(nvm_version "$2")" else - VERSION="$2" + # Handle options + while [[ $# > 0 ]]; do + key="$1" + shift + case $key in + --print-paths) + PRINT_PATHS=true + ;; + + *) + if [ "_$key" != '_system' ]; then + VERSION="$(nvm_version "$key")" + else + VERSION="$key" + fi + break + ;; + esac + done fi + if [ -z "$VERSION" ]; then nvm help return 127 @@ -822,7 +837,7 @@ nvm() { return 127 fi elif [ "_$VERSION" = "_∞" ]; then - echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2 + echo "The alias \"$1\" leads to an infinite loop. Aborting." >&2 return 8 fi @@ -858,6 +873,12 @@ nvm() { if [ "$NVM_SYMLINK_CURRENT" = true ]; then rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" fi + if [ $PRINT_PATHS ]; then + echo PATH=$PATH + echo NODE_PATH=$NODE_PATH + echo NVM_PATH=$NVM_PATH + echo NVM_BIN=$NVM_BIN + fi echo "Now using node $VERSION" ;; "run" )