Skip to content

Commit 714f6df

Browse files
authored
fix: avoid polluting the global namespace (#347)
Signed-off-by: Wenxuan Zhang <[email protected]>
1 parent 2eda2a4 commit 714f6df

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

forgit.plugin.zsh

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ if [[ -n "$ZSH_VERSION" ]]; then
1010
0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
1111
# shellcheck disable=2277,2296,2298
1212
0="${${(M)0:#/*}:-$PWD/$0}"
13-
INSTALL_DIR="${0:h}"
13+
FORGIT_INSTALL_DIR="${0:h}"
1414
elif [[ -n "$BASH_VERSION" ]]; then
15-
INSTALL_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
15+
FORGIT_INSTALL_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
1616
else
1717
forgit::error "Only zsh and bash are supported"
1818
fi
19-
FORGIT="$INSTALL_DIR/bin/git-forgit"
19+
20+
export FORGIT_INSTALL_DIR
21+
FORGIT="$FORGIT_INSTALL_DIR/bin/git-forgit"
2022

2123
# backwards compatibility:
2224
# export all user-defined FORGIT variables to make them available in git-forgit
@@ -35,6 +37,7 @@ set | awk -F '=' '{ print $1 }' | grep FORGIT_ | while read -r var; do
3537
export "$var"
3638
fi
3739
done
40+
unset unexported_vars
3841
[[ -n "$BASH_VERSION" ]] && set +o posix
3942

4043
# register shell functions
@@ -130,8 +133,6 @@ forgit::ignore::clean() {
130133
"$FORGIT" ignore_clean "$@"
131134
}
132135

133-
export FORGIT_INSTALL_DIR=$INSTALL_DIR
134-
135136
# register aliases
136137
# shellcheck disable=SC2139
137138
if [[ -z "$FORGIT_NO_ALIASES" ]]; then

0 commit comments

Comments
 (0)