Skip to content

Commit de428ee

Browse files
authored
Support shells with "set -u" (#345)
1 parent dc114e1 commit de428ee

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

nodeenv.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -1261,17 +1261,17 @@ def main():
12611261
12621262
deactivate_node () {
12631263
# reset old environment variables
1264-
if [ -n "$_OLD_NODE_VIRTUAL_PATH" ] ; then
1265-
PATH="$_OLD_NODE_VIRTUAL_PATH"
1264+
if [ -n "${_OLD_NODE_VIRTUAL_PATH:-}" ] ; then
1265+
PATH="${_OLD_NODE_VIRTUAL_PATH:-}"
12661266
export PATH
12671267
unset _OLD_NODE_VIRTUAL_PATH
12681268
1269-
NODE_PATH="$_OLD_NODE_PATH"
1269+
NODE_PATH="${_OLD_NODE_PATH:-}"
12701270
export NODE_PATH
12711271
unset _OLD_NODE_PATH
12721272
1273-
NPM_CONFIG_PREFIX="$_OLD_NPM_CONFIG_PREFIX"
1274-
npm_config_prefix="$_OLD_npm_config_prefix"
1273+
NPM_CONFIG_PREFIX="${_OLD_NPM_CONFIG_PREFIX:-}"
1274+
npm_config_prefix="${_OLD_npm_config_prefix:-}"
12751275
export NPM_CONFIG_PREFIX
12761276
export npm_config_prefix
12771277
unset _OLD_NPM_CONFIG_PREFIX
@@ -1281,18 +1281,18 @@ def main():
12811281
# This should detect bash and zsh, which have a hash command that must
12821282
# be called to get it to forget past commands. Without forgetting
12831283
# past commands the $PATH changes we made may not be respected
1284-
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
1284+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
12851285
hash -r
12861286
fi
12871287
1288-
if [ -n "$_OLD_NODE_VIRTUAL_PS1" ] ; then
1289-
PS1="$_OLD_NODE_VIRTUAL_PS1"
1288+
if [ -n "${_OLD_NODE_VIRTUAL_PS1:-}" ] ; then
1289+
PS1="${_OLD_NODE_VIRTUAL_PS1:-}"
12901290
export PS1
12911291
unset _OLD_NODE_VIRTUAL_PS1
12921292
fi
12931293
12941294
unset NODE_VIRTUAL_ENV
1295-
if [ ! "$1" = "nondestructive" ] ; then
1295+
if [ ! "${1:-}" = "nondestructive" ] ; then
12961296
# Self destruct!
12971297
unset -f deactivate_node
12981298
fi
@@ -1306,7 +1306,7 @@ def main():
13061306
cut -d ' ' -f 1 | grep -v npm`
13071307
else
13081308
local npmls="npm ls -g"
1309-
if [ "$1" = "-l" ]; then
1309+
if [ "${1:-}" = "-l" ]; then
13101310
npmls="npm ls"
13111311
shift
13121312
fi
@@ -1326,7 +1326,7 @@ def main():
13261326
13271327
# find the directory of this script
13281328
# http://stackoverflow.com/a/246128
1329-
if [ "${BASH_SOURCE}" ] ; then
1329+
if [ "${BASH_SOURCE:-}" ] ; then
13301330
SOURCE="${BASH_SOURCE[0]}"
13311331
13321332
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
@@ -1346,28 +1346,28 @@ def main():
13461346
PATH="$NODE_VIRTUAL_ENV/lib/node_modules/.bin:$NODE_VIRTUAL_ENV/__BIN_NAME__:$PATH"
13471347
export PATH
13481348
1349-
_OLD_NODE_PATH="$NODE_PATH"
1349+
_OLD_NODE_PATH="${NODE_PATH:-}"
13501350
NODE_PATH="$NODE_VIRTUAL_ENV/__MOD_NAME__"
13511351
export NODE_PATH
13521352
1353-
_OLD_NPM_CONFIG_PREFIX="$NPM_CONFIG_PREFIX"
1354-
_OLD_npm_config_prefix="$npm_config_prefix"
1353+
_OLD_NPM_CONFIG_PREFIX="${NPM_CONFIG_PREFIX:-}"
1354+
_OLD_npm_config_prefix="${npm_config_prefix:-}"
13551355
NPM_CONFIG_PREFIX="__NPM_CONFIG_PREFIX__"
13561356
npm_config_prefix="__NPM_CONFIG_PREFIX__"
13571357
export NPM_CONFIG_PREFIX
13581358
export npm_config_prefix
13591359
1360-
if [ -z "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
1361-
_OLD_NODE_VIRTUAL_PS1="$PS1"
1360+
if [ -z "${NODE_VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
1361+
_OLD_NODE_VIRTUAL_PS1="${PS1:-}"
13621362
if [ "x__NODE_VIRTUAL_PROMPT__" != x ] ; then
1363-
PS1="__NODE_VIRTUAL_PROMPT__ $PS1"
1363+
PS1="__NODE_VIRTUAL_PROMPT__ ${PS1:-}"
13641364
else
13651365
if [ "`basename \"$NODE_VIRTUAL_ENV\"`" = "__" ] ; then
13661366
# special case for Aspen magic directories
13671367
# see http://www.zetadev.com/software/aspen/
1368-
PS1="[`basename \`dirname \"$NODE_VIRTUAL_ENV\"\``] $PS1"
1368+
PS1="[`basename \`dirname \"$NODE_VIRTUAL_ENV\"\``] ${PS1:-}"
13691369
else
1370-
PS1="(`basename \"$NODE_VIRTUAL_ENV\"`) $PS1"
1370+
PS1="(`basename \"$NODE_VIRTUAL_ENV\"`) ${PS1:-}"
13711371
fi
13721372
fi
13731373
export PS1
@@ -1376,7 +1376,7 @@ def main():
13761376
# This should detect bash and zsh, which have a hash command that must
13771377
# be called to get it to forget past commands. Without forgetting
13781378
# past commands the $PATH changes we made may not be respected
1379-
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
1379+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
13801380
hash -r
13811381
fi
13821382
"""

0 commit comments

Comments
 (0)