Skip to content

Commit

Permalink
fix: don't override existing ASDF_DIR (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Nielsen committed Nov 2, 2021
1 parent 69ff2d0 commit 73efc9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions asdf.sh
Expand Up @@ -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'

Expand All @@ -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
3 changes: 3 additions & 0 deletions test/version_commands.bats
Expand Up @@ -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() {
Expand Down

0 comments on commit 73efc9f

Please sign in to comment.