Add support for `--silent` to `nvm run` and `nvm exec`.

Fixes #842.
Jordan Harband 2015-09-23 05:16:45 -07:00
parent 7496a24bd6
commit eb81fba8f7
1 changed files with 39 additions and 24 deletions

63
nvm.sh
View File

@ -1279,27 +1279,27 @@ nvm() {
echo ' - custom aliases you define with `nvm alias foo`' echo ' - custom aliases you define with `nvm alias foo`'
echo echo
echo 'Usage:' echo 'Usage:'
echo ' nvm help Show this message' echo ' nvm help Show this message'
echo ' nvm --version Print out the latest released version of nvm' echo ' nvm --version Print out the latest released version of nvm'
echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available' echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available'
echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>' echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
echo ' nvm uninstall <version> Uninstall a version' echo ' nvm uninstall <version> Uninstall a version'
echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available' echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
echo ' nvm exec <version> [<command>] Run <command> on <version>. Uses .nvmrc if available for <version>' echo ' nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available'
echo ' nvm run <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available for <version>' echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
echo ' nvm current Display currently activated version' echo ' nvm current Display currently activated version'
echo ' nvm ls List installed versions' echo ' nvm ls List installed versions'
echo ' nvm ls <version> List versions matching a given description' echo ' nvm ls <version> List versions matching a given description'
echo ' nvm ls-remote List remote versions available for install' echo ' nvm ls-remote List remote versions available for install'
echo ' nvm version <version> Resolve the given description to a single local version' echo ' nvm version <version> Resolve the given description to a single local version'
echo ' nvm version-remote <version> Resolve the given description to a single remote version' echo ' nvm version-remote <version> Resolve the given description to a single remote version'
echo ' nvm deactivate Undo effects of `nvm` on current shell' echo ' nvm deactivate Undo effects of `nvm` on current shell'
echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>' echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>' echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
echo ' nvm unalias <name> Deletes the alias named <name>' echo ' nvm unalias <name> Deletes the alias named <name>'
echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version' echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
echo ' nvm unload Unload `nvm` from shell' echo ' nvm unload Unload `nvm` from shell'
echo ' nvm which [<version>] Display path to installed node version. Uses .nvmrc if available' echo ' nvm which [<version>] Display path to installed node version. Uses .nvmrc if available'
echo echo
echo 'Example:' echo 'Example:'
echo ' nvm install v0.10.32 Install a specific version number' echo ' nvm install v0.10.32 Install a specific version number'
@ -1659,6 +1659,14 @@ nvm() {
has_checked_nvmrc=0 has_checked_nvmrc=0
# run given version of node # run given version of node
shift shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm_rc_version && has_checked_nvmrc=1 nvm_rc_version && has_checked_nvmrc=1
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
@ -1713,11 +1721,11 @@ nvm() {
fi fi
EXIT_CODE="$?" EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then 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)" OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
EXIT_CODE="$?" EXIT_CODE="$?"
else 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)" OUTPUT="$(nvm use "$VERSION" >/dev/null && node $ARGS)"
EXIT_CODE="$?" EXIT_CODE="$?"
fi fi
@ -1732,6 +1740,13 @@ nvm() {
"exec" ) "exec" )
shift shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
local provided_version local provided_version
provided_version="$1" provided_version="$1"
if [ -n "$provided_version" ]; then if [ -n "$provided_version" ]; then
@ -1751,7 +1766,7 @@ nvm() {
return $EXIT_CODE return $EXIT_CODE
fi 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 "$@" NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
;; ;;
"ls" | "list" ) "ls" | "list" )