From d1782f456eac16f60ed9a71eb0c57ae593e86865 Mon Sep 17 00:00:00 2001 From: Jose Luis Salas Date: Sun, 16 Sep 2018 18:39:21 +0200 Subject: [PATCH] Retrieve asdf_data_dir from environment variable --- asdf.sh | 2 +- lib/utils.sh | 15 ++++++--------- test/utils.bats | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/asdf.sh b/asdf.sh index 6da4bf7f..6595c63c 100644 --- a/asdf.sh +++ b/asdf.sh @@ -17,7 +17,7 @@ ASDF_DIR="$(dirname "$current_script_path")" # replace all occurrences - ${parameter//pattern/string} ASDF_BIN="${ASDF_DIR}/bin" ASDF_SHIMS="${ASDF_DIR}/shims" -ASDF_USER_SHIMS="${HOME}/.asdf/shims" +ASDF_USER_SHIMS="${ASDF_DATA_DIR:-$HOME/.asdf}" [[ ":$PATH:" == *":${ASDF_BIN}:"* ]] && PATH="${PATH//$ASDF_BIN:/}" [[ ":$PATH:" == *":${ASDF_SHIMS}:"* ]] && PATH="${PATH//$ASDF_SHIMS:/}" [[ ":$PATH:" == *":${ASDF_USER_SHIMS}:"* ]] && PATH="${PATH//$ASDF_USER_SHIMS:/}" diff --git a/lib/utils.sh b/lib/utils.sh index 83205fa7..27f425b3 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -33,10 +33,10 @@ get_install_type(){ asdf_data_dir(){ local data_dir - if [ "$(get_install_type)" = "user" ]; then - data_dir="${HOME}/.asdf" + if ! [ -z "${ASDF_DATA_DIR}" ]; then + data_dir="${ASDF_DATA_DIR}" else - data_dir="$(asdf_dir)" + data_dir="$HOME/.asdf" fi echo "$data_dir" @@ -65,16 +65,13 @@ list_installed_versions() { local plugin_path plugin_path=$(get_plugin_path "$plugin_name") - local install_dir - install_dir="$(asdf_data_dir)/installs" - local plugin_installs_path - plugin_installs_path=${install_dir}/${plugin_name} + plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}" if [ -d "$plugin_installs_path" ]; then - # shellcheck disable=SC2045 + # shellcheck disable=SC2045 for install in $(ls -d "${plugin_installs_path}"/*/ 2>/dev/null); do - basename "$install" | sed 's/^ref-/ref:/' + basename "$install" | sed 's/^ref-/ref:/' done fi } diff --git a/test/utils.bats b/test/utils.bats index a86d41b5..31d6b4c9 100644 --- a/test/utils.bats +++ b/test/utils.bats @@ -125,11 +125,11 @@ teardown() { } @test "asdf_data_dir should return user dir if configured" { - echo "install_type = user" > $HOME/.asdfrc + ASDF_DATA_DIR="/tmp/wadus" run asdf_data_dir [ "$status" -eq 0 ] - [ "$output" = "$HOME/.asdf" ] + [ "$output" = "$ASDF_DATA_DIR" ] } @test "find_version should return \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {