Skip to content

Commit

Permalink
wip: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Oct 17, 2022
1 parent cd31d57 commit c85f5c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
26 changes: 26 additions & 0 deletions bin/asdf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ asdf_cmd() {
exit 1
fi

# XDG Compliance
ASDF_CONFIG_FILE=$(asdf_config_file)
export ASDF_CONFIG_FILE

ASDF_DIR=$(asdf_dir)
export ASDF_DIR

ASDF_DATA_DIR=$(asdf_data_dir)
export ASDF_DATA_DIR

if [ "$1" = '--internal-get-asdf-config-file' ]; then
printf '%s\n' "$ASDF_CONFIG_FILE"
exit 0
elif [ "$1" = '--internal-get-asdf-dir' ]; then
printf '%s\n' "$ASDF_DIR"
exit 0
elif [ "$1" = '--internal-get-asdf-data-dir' ]; then
printf '%s\n' "$ASDF_DATA_DIR"
exit 0
fi

mkdir -p "${ASDF_CONFIG_FILE%/*}"
mkdir -p "${ASDF_DIR}"
mkdir -p "${ASDF_DATA_DIR}"


IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_asdf_cmd "$@")"
if [ -z "$ASDF_CMD_FILE" ]; then
IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_plugin_cmd "$@")"
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
21 changes: 18 additions & 3 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ asdf_dir() {
printf "%s\\n" "$ASDF_DIR"
}

asdf_config_file() {
if [ -n "$ASDF_CONFIG_FILE" ]; then
printf '%s' "$ASDF_CONFIG_FILE"
elif [ -f "$HOME/.asdfrc" ]; then
printf '%s' "$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_repository_url() {
printf "https://github.com/asdf-vm/asdf-plugins.git\\n"
}
Expand All @@ -41,10 +53,12 @@ asdf_data_dir() {

if [ -n "${ASDF_DATA_DIR}" ]; then
data_dir="${ASDF_DATA_DIR}"
elif [ -n "$HOME" ]; then
elif [ -d "$HOME/.asdf" ]; then
data_dir="$HOME/.asdf"
elif [ "${XDG_STATE_HOME::1}" = '/' ]; then
printf '%s\n' "$XDG_STATE_HOME/asdf"
else
data_dir=$(asdf_dir)
printf '%s\n' "$HOME/.local/state/asdf"
fi

printf "%s\\n" "$data_dir"
Expand Down Expand Up @@ -376,7 +390,8 @@ get_asdf_config_value_from_file() {

get_asdf_config_value() {
local key=$1
local config_path=${ASDF_CONFIG_FILE:-"$HOME/.asdfrc"}
local config_path
config_path=$(asdf_config_file)
local default_config_path=${ASDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}

local local_config_path
Expand Down

0 comments on commit c85f5c2

Please sign in to comment.