fix: avoid polluting the global namespace (#347)

Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
This commit is contained in:
Wenxuan 2024-02-06 14:21:51 +08:00 committed by GitHub
parent 2eda2a457a
commit 714f6dfec1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,13 +10,15 @@ if [[ -n "$ZSH_VERSION" ]]; then
0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
# shellcheck disable=2277,2296,2298
0="${${(M)0:#/*}:-$PWD/$0}"
INSTALL_DIR="${0:h}"
FORGIT_INSTALL_DIR="${0:h}"
elif [[ -n "$BASH_VERSION" ]]; then
INSTALL_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
FORGIT_INSTALL_DIR="$(dirname -- "${BASH_SOURCE[0]}")"
else
forgit::error "Only zsh and bash are supported"
fi
FORGIT="$INSTALL_DIR/bin/git-forgit"
export FORGIT_INSTALL_DIR
FORGIT="$FORGIT_INSTALL_DIR/bin/git-forgit"
# backwards compatibility:
# 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
export "$var"
fi
done
unset unexported_vars
[[ -n "$BASH_VERSION" ]] && set +o posix
# register shell functions
@ -130,8 +133,6 @@ forgit::ignore::clean() {
"$FORGIT" ignore_clean "$@"
}
export FORGIT_INSTALL_DIR=$INSTALL_DIR
# register aliases
# shellcheck disable=SC2139
if [[ -z "$FORGIT_NO_ALIASES" ]]; then