Merge pull request #780 from alanmquach/silent-source
Adding --silent option for nvm use, and using it to disable processing certain output to speed up shell startup Relates to #781.
commit
60c2f3705e
25
nvm.sh
25
nvm.sh
|
@ -1187,7 +1187,7 @@ nvm() {
|
||||||
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 " nvm uninstall <version> Uninstall a version"
|
echo " nvm uninstall <version> Uninstall a version"
|
||||||
echo " nvm use <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 run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"
|
echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"
|
||||||
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"
|
||||||
|
@ -1445,6 +1445,13 @@ nvm() {
|
||||||
;;
|
;;
|
||||||
"use" )
|
"use" )
|
||||||
local PROVIDED_VERSION
|
local PROVIDED_VERSION
|
||||||
|
local silent
|
||||||
|
silent=0
|
||||||
|
if [ "$2" = '--silent' ]; then
|
||||||
|
silent=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
nvm_rc_version
|
nvm_rc_version
|
||||||
if [ -n "$NVM_RC_VERSION" ]; then
|
if [ -n "$NVM_RC_VERSION" ]; then
|
||||||
|
@ -1463,17 +1470,25 @@ nvm() {
|
||||||
|
|
||||||
if [ "_$VERSION" = '_system' ]; then
|
if [ "_$VERSION" = '_system' ]; then
|
||||||
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
|
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"
|
echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then
|
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
|
echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "System version of node not found." >&2
|
echo "System version of node not found." >&2
|
||||||
|
fi
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
elif [ "_$VERSION" = "_∞" ]; then
|
elif [ "_$VERSION" = "_∞" ]; then
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2
|
echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2
|
||||||
|
fi
|
||||||
return 8
|
return 8
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1510,10 +1525,14 @@ nvm() {
|
||||||
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
|
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
|
||||||
fi
|
fi
|
||||||
if nvm_is_iojs_version "$VERSION"; then
|
if nvm_is_iojs_version "$VERSION"; then
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
|
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
if [ $silent -ne 1 ]; then
|
||||||
echo "Now using node $VERSION$(nvm_print_npm_version)"
|
echo "Now using node $VERSION$(nvm_print_npm_version)"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
"run" )
|
"run" )
|
||||||
local provided_version
|
local provided_version
|
||||||
|
@ -1882,9 +1901,9 @@ if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
|
||||||
nvm install >/dev/null
|
nvm install >/dev/null
|
||||||
fi
|
fi
|
||||||
elif [ -n "$VERSION" ]; then
|
elif [ -n "$VERSION" ]; then
|
||||||
nvm use "$VERSION" >/dev/null
|
nvm use --silent "$VERSION" >/dev/null
|
||||||
elif nvm_rc_version >/dev/null 2>&1; then
|
elif nvm_rc_version >/dev/null 2>&1; then
|
||||||
nvm use >/dev/null
|
nvm use --silent >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
} # this ensures the entire script is downloaded #
|
} # this ensures the entire script is downloaded #
|
||||||
|
|
|
@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
|
||||||
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
||||||
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use --silent foo 2>&1)"
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
||||||
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
|
||||||
|
|
||||||
cleanup;
|
cleanup;
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
|
||||||
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
||||||
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use --silent foo 2>&1)"
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
||||||
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
|
||||||
|
|
||||||
cleanup;
|
cleanup;
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,15 @@ nvm_has_system_node() { return 0; }
|
||||||
nvm_print_npm_version() { return ' (npm v1.2.3)'; }
|
nvm_print_npm_version() { return ' (npm v1.2.3)'; }
|
||||||
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
|
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
|
||||||
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"
|
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"
|
||||||
|
EXPECTED_OUTPUT=""
|
||||||
|
[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node or --silent was not silent"
|
||||||
|
|
||||||
nvm_has_system_node() { return 1; }
|
nvm_has_system_node() { return 1; }
|
||||||
nvm_print_npm_version() { return ''; }
|
nvm_print_npm_version() { return ''; }
|
||||||
EXPECTED_OUTPUT="System version of node not found."
|
EXPECTED_OUTPUT="System version of node not found."
|
||||||
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"
|
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"
|
||||||
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
|
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
|
||||||
|
EXPECTED_OUTPUT=""
|
||||||
|
[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found or --silent was not silent"
|
||||||
|
nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent"
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,9 @@ EXPECTED_OUTPUT="iojs-v1.0.1"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|| die "'nvm use iojs' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|| die "'nvm use iojs' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use --silent iojs)"
|
||||||
|
EXPECTED_OUTPUT=""
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use --silent iojs' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
|
@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version stable)"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|| die "'nvm use node' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|| die "'nvm use node' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use --silent node)"
|
||||||
|
EXPECTED_OUTPUT=""
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use --silent node' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
|
@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version v1.0.0)"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|| die "'nvm use v1.0.0' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|| die "'nvm use v1.0.0' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use --silent 'v1.0.0')"
|
||||||
|
EXPECTED_OUTPUT=""
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use --silent v1.0.0' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
Loading…
Reference in New Issue