Skip to content

Commit

Permalink
wip: wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed May 27, 2023
1 parent 684f4f0 commit f8cf5fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
11 changes: 11 additions & 0 deletions bin/asdf
Original file line number Diff line number Diff line change
Expand Up @@ -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% *}
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
22 changes: 15 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f8cf5fa

Please sign in to comment.