From 73efc9fa97744c49c5004ee8bb9b6064b6ce22f2 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 2 Nov 2021 17:47:43 -0500 Subject: [PATCH] fix: don't override existing ASDF_DIR (#1008) --- asdf.sh | 20 ++++++++++++-------- test/version_commands.bats | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/asdf.sh b/asdf.sh index 7450c183..ff6ecfd9 100644 --- a/asdf.sh +++ b/asdf.sh @@ -3,16 +3,18 @@ # For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path. # For Zsh and others, $0 (the path to the shell or script) will be used. _under="$_" -if [ "${BASH_SOURCE[0]}" != "" ]; then - current_script_path="${BASH_SOURCE[0]}" -elif [[ "$_under" == *".sh" ]]; then - current_script_path="$_under" -else - current_script_path="$0" -fi +if [ -z "$ASDF_DIR" ]; then + if [ -n "${BASH_SOURCE[0]}" ]; then + current_script_path="${BASH_SOURCE[0]}" + elif [[ "$_under" == *".sh" ]]; then + current_script_path="$_under" + else + current_script_path="$0" + fi + ASDF_DIR="$(dirname "$current_script_path")" +fi export ASDF_DIR -ASDF_DIR="$(dirname "$current_script_path")" # shellcheck disable=SC2016 [ -d "$ASDF_DIR" ] || echo '$ASDF_DIR is not a directory' @@ -31,3 +33,5 @@ PATH="${ASDF_USER_SHIMS}:$PATH" # shellcheck source=lib/asdf.sh # Load the asdf wrapper function . "${ASDF_DIR}/lib/asdf.sh" + +unset _under current_script_path ASDF_BIN ASDF_USER_SHIMS diff --git a/test/version_commands.bats b/test/version_commands.bats index 35fcb7a3..a0aef1fe 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -21,6 +21,9 @@ setup() { mkdir -p $CHILD_DIR cd $PROJECT_DIR + + # asdf lib needed to run asdf.sh + cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/ } teardown() {