Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Full compliance with XDG Base Directory Specification #1351

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bin/asdf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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% *}
Expand Down
3 changes: 2 additions & 1 deletion completions/_asdf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@ 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}"
printf '%s\n' "${ASDF_DATA_DIR}"
elif [ -n "$HOME" ]; then
data_dir="$HOME/.asdf"
if [ -d "$HOME/.asdf" ]; then
printf '%s\n' "$HOME/.asdf"
elif [ "${XDG_DATA_HOME::1}" = '/' ]; then
printf '%s\n' "$XDG_DATA_HOME/asdf"
else
printf '%s\n' "$HOME/.local/state/asdf"
fi
else
data_dir=$(asdf_dir)
fi

printf "%s\n" "$data_dir"
}

asdf_dir() {
Expand Down