Skip to content

Commit

Permalink
fix: avoid polluting the global namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Wenxuan Zhang <wenxuangm@gmail.com>
  • Loading branch information
wfxr committed Feb 6, 2024
1 parent 63fd2ba commit eae736e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions forgit.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ 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
unexported_vars=0
local unexported_vars=0
# Set posix mode in bash to only get variables, see #256.
[[ -n "$BASH_VERSION" ]] && set -o posix
set | awk -F '=' '{ print $1 }' | grep FORGIT_ | while read -r var; do
Expand Down Expand Up @@ -130,8 +132,6 @@ forgit::ignore::clean() {
"$FORGIT" ignore_clean "$@"
}

export FORGIT_INSTALL_DIR=$INSTALL_DIR

# register aliases
# shellcheck disable=SC2139
if [[ -z "$FORGIT_NO_ALIASES" ]]; then
Expand Down

0 comments on commit eae736e

Please sign in to comment.