Skip to content

Commit 3a6a061

Browse files
authored
[change_hermit_env] Gracefully handle set -u in change_hermit_env (#443)
For my own sanity's sake, I use `set -u` as part of my zsh config. However, hermit's `change_hermit_env` command fails when this is enabled; this PR fixes the hook so that when variables aren't set it won't emit the following error: ```sh % cd ~/tmp/testing change_hermit_env:3: HERMIT_ENV: parameter not set % ```
1 parent cc90510 commit 3a6a061

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

shell/files/sh_common_hooks.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
change_hermit_env() {
22
local CUR=${PWD}
33
while [ "$CUR" != "/" ]; do
4-
if [ "${CUR}" -ef "${HERMIT_ENV}" ]; then return; fi
4+
if [ -n "${HERMIT_ENV+_}" ] && [ "${CUR}" -ef "${HERMIT_ENV}" ]; then
5+
return
6+
fi
57
if [ -f "${CUR}/bin/activate-hermit" ]; then
68
if [ -n "${HERMIT_ENV+_}" ]; then type _hermit_deactivate &>/dev/null && _hermit_deactivate; fi
79
# shellcheck source=files/activate-hermit
8-
if ! [ "${CUR}" -ef "${DEACTIVATED_HERMIT}" ]; then
10+
if [ -z "${DEACTIVATED_HERMIT+_}" ] || ! [ "${CUR}" -ef "${DEACTIVATED_HERMIT}" ]; then
911
if "${HERMIT_ROOT_BIN:-"$HOME/bin/hermit"}" --quiet validate env "${CUR}"; then
1012
. "${CUR}/bin/activate-hermit"
1113
fi

0 commit comments

Comments
 (0)