From eb81fba8f7fda7342472256040597a8e59261552 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 23 Sep 2015 05:16:45 -0700 Subject: [PATCH] Add support for `--silent` to `nvm run` and `nvm exec`. Fixes #842. --- nvm.sh | 63 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/nvm.sh b/nvm.sh index dfa28b8..1ef9b08 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1279,27 +1279,27 @@ nvm() { echo ' - custom aliases you define with `nvm alias foo`' 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 ' --reinstall-packages-from= When installing, reinstall packages installed in ' - echo ' nvm uninstall Uninstall a version' - echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' - echo ' nvm exec [] Run on . Uses .nvmrc if available for ' - echo ' nvm run [] Run `node` on 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 version Resolve the given description to a single local version' - echo ' nvm version-remote Resolve the given description to a single remote version' - 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 reinstall-packages Reinstall global `npm` packages contained in to current version' - echo ' nvm unload Unload `nvm` from shell' - echo ' nvm which [] Display path to installed node version. Uses .nvmrc if available' + 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 ' --reinstall-packages-from= When installing, reinstall packages installed in ' + echo ' nvm uninstall Uninstall a version' + echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' + echo ' nvm exec [--silent] [] Run on . Uses .nvmrc if available' + echo ' nvm run [--silent] [] Run `node` on with as arguments. Uses .nvmrc if available' + 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 version Resolve the given description to a single local version' + echo ' nvm version-remote Resolve the given description to a single remote version' + 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 reinstall-packages Reinstall global `npm` packages contained in to current version' + echo ' nvm unload Unload `nvm` from shell' + echo ' nvm which [] Display path to installed node version. Uses .nvmrc if available' echo echo 'Example:' echo ' nvm install v0.10.32 Install a specific version number' @@ -1659,6 +1659,14 @@ nvm() { has_checked_nvmrc=0 # run given version of node shift + + local NVM_SILENT + NVM_SILENT=0 + if [ "_$1" = "_--silent" ]; then + NVM_SILENT=1 + shift + fi + if [ $# -lt 1 ]; then nvm_rc_version && has_checked_nvmrc=1 if [ -n "$NVM_RC_VERSION" ]; then @@ -1713,11 +1721,11 @@ nvm() { fi EXIT_CODE="$?" elif [ "$NVM_IOJS" = true ]; then - echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)" + [ $NVM_SILENT -eq 1 ] || echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)" OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)" EXIT_CODE="$?" else - echo "Running node $VERSION$(nvm_print_npm_version)" + [ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)" OUTPUT="$(nvm use "$VERSION" >/dev/null && node $ARGS)" EXIT_CODE="$?" fi @@ -1732,6 +1740,13 @@ nvm() { "exec" ) shift + local NVM_SILENT + NVM_SILENT=0 + if [ "_$1" = "_--silent" ]; then + NVM_SILENT=1 + shift + fi + local provided_version provided_version="$1" if [ -n "$provided_version" ]; then @@ -1751,7 +1766,7 @@ nvm() { return $EXIT_CODE fi - echo "Running node $VERSION$(nvm_print_npm_version)" + [ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)" NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@" ;; "ls" | "list" )