diff --git a/bin/asdf b/bin/asdf index f2614259e..34e0d83fc 100755 --- a/bin/asdf +++ b/bin/asdf @@ -81,6 +81,17 @@ asdf_cmd() { ASDF_DIR=$(asdf_dir) export ASDF_DIR + if [ "$1" = '--internal-get-asdf-config-file' ]; then + printf '%s\n' "$ASDF_CONFIG_FILE" + exit 0 + elif [ "$1" = '--internal-get-asdf-data-dir' ]; then + printf '%s\n' "$ASDF_DATA_DIR" + exit 0 + elif [ "$1" = '--internal-get-asdf-dir' ]; then + printf '%s\n' "$ASDF_DIR" + exit 0 + fi + local result= result="$(find_asdf_cmd "$@")" ASDF_CMD_FILE=${result% *} diff --git a/completions/_asdf b/completions/_asdf index f65733547..f91650375 100755 --- a/completions/_asdf +++ b/completions/_asdf @@ -2,7 +2,8 @@ #description tool to manage versions of multiple runtimes local curcontext="$curcontext" state state_descr line subcmd -local asdf_dir="${ASDF_DATA_DIR:-$HOME/.asdf}" +local asdf_dir= +asdf_dir=$(asdf --internal-get-asdf-dir) local -a asdf_commands asdf_commands=( # 'asdf help' lists commands with help text diff --git a/lib/utils.bash b/lib/utils.bash index c52470b3d..70fbf4d55 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -21,21 +21,29 @@ asdf_tool_versions_filename() { } asdf_config_file() { - printf '%s\n' "${ASDF_CONFIG_FILE:-$HOME/.asdfrc}" + if [ -n "$ASDF_CONFIG_FILE" ]; then + printf '%s\n' "$ASDF_CONFIG_FILE" + elif [ -f "$HOME/.asdfrc" ]; then + printf '%s\n' "$HOME/.asdfrc" + elif [ "${XDG_CONFIG_HOME::1}" = '/' ]; then + printf '%s\n' "$XDG_CONFIG_HOME/asdf/asdfrc" + else + printf '%s\n' "$HOME/.config/asdf/asdfrc" + fi } asdf_data_dir() { local data_dir if [ -n "${ASDF_DATA_DIR}" ]; then - data_dir="${ASDF_DATA_DIR}" - elif [ -n "$HOME" ]; then - data_dir="$HOME/.asdf" + printf '%s\n' "${ASDF_DATA_DIR}" + elif [ -d "$HOME/.asdf" ]; then + printf '%s\n' "$HOME/.asdf" + elif [ "${XDG_DATA_HOME::1}" = '/' ]; then + printf '%s\n' "$XDG_DATA_HOME/asdf" else - data_dir=$(asdf_dir) + printf '%s\n' "$HOME/.local/state/asdf" fi - - printf "%s\n" "$data_dir" } asdf_dir() {