Skip to content

Commit 4054162

Browse files
authored
Fix errors when set -u is set in the user's shell (#350)
1 parent 9a57cd7 commit 4054162

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

bin/pyenv-virtualenv-init

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ esac
129129
if [[ "$shell" != "fish" ]]; then
130130
cat <<EOS
131131
local ret=\$?
132-
if [ -n "\$VIRTUAL_ENV" ]; then
132+
if [ -n "\${VIRTUAL_ENV-}" ]; then
133133
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
134134
else
135135
eval "\$(pyenv sh-activate --quiet || true)" || true
@@ -141,8 +141,8 @@ EOS
141141
case "$shell" in
142142
bash )
143143
cat <<EOS
144-
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
145-
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
144+
if ! [[ "\${PROMPT_COMMAND-}" =~ _pyenv_virtualenv_hook ]]; then
145+
PROMPT_COMMAND="_pyenv_virtualenv_hook;\${PROMPT_COMMAND-}"
146146
fi
147147
EOS
148148
;;

test/init.bats

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ load test_helper
66
unset PYENV_SHELL
77
SHELL=/bin/false run pyenv-virtualenv-init -
88
assert_success
9-
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
9+
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
1010
}
1111

1212
@test "detect parent shell from script (sh)" {
@@ -15,7 +15,7 @@ load test_helper
1515
chmod +x ${TMP}/script.sh
1616
run ${TMP}/script.sh
1717
assert_success
18-
assert_output_contains_not ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
18+
assert_output_contains_not ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
1919
rm -f "${TMP}/script.sh"
2020
}
2121

@@ -25,7 +25,7 @@ load test_helper
2525
chmod +x ${TMP}/script.sh
2626
run ${TMP}/script.sh
2727
assert_success
28-
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
28+
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;${PROMPT_COMMAND-}"'
2929
rm -f "${TMP}/script.sh"
3030
}
3131

@@ -54,15 +54,15 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
5454
export PYENV_VIRTUALENV_INIT=1;
5555
_pyenv_virtualenv_hook() {
5656
local ret=\$?
57-
if [ -n "\$VIRTUAL_ENV" ]; then
57+
if [ -n "\${VIRTUAL_ENV-}" ]; then
5858
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
5959
else
6060
eval "\$(pyenv sh-activate --quiet || true)" || true
6161
fi
6262
return \$ret
6363
};
64-
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
65-
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
64+
if ! [[ "\${PROMPT_COMMAND-}" =~ _pyenv_virtualenv_hook ]]; then
65+
PROMPT_COMMAND="_pyenv_virtualenv_hook;\${PROMPT_COMMAND-}"
6666
fi
6767
EOS
6868
}
@@ -95,7 +95,7 @@ export PATH="${TMP}/pyenv/plugins/pyenv-virtualenv/shims:\${PATH}";
9595
export PYENV_VIRTUALENV_INIT=1;
9696
_pyenv_virtualenv_hook() {
9797
local ret=\$?
98-
if [ -n "\$VIRTUAL_ENV" ]; then
98+
if [ -n "\${VIRTUAL_ENV-}" ]; then
9999
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
100100
else
101101
eval "\$(pyenv sh-activate --quiet || true)" || true

0 commit comments

Comments
 (0)