2017-03-07 11:18:20 -07:00
|
|
|
# We shouldn't rely on the user's grep settings to be correct. If we set these
|
|
|
|
# here anytime asdf invokes grep it will be invoked with these options
|
2017-09-03 09:11:20 -07:00
|
|
|
# shellcheck disable=SC2034
|
2017-03-07 11:18:20 -07:00
|
|
|
GREP_OPTIONS="--color=never"
|
2017-09-03 09:14:57 -07:00
|
|
|
# shellcheck disable=SC2034
|
2017-03-07 11:18:20 -07:00
|
|
|
GREP_COLORS=
|
|
|
|
|
2014-11-29 09:28:11 -07:00
|
|
|
asdf_version() {
|
2019-11-26 21:02:39 -07:00
|
|
|
local version git_rev
|
2021-07-12 18:32:37 -07:00
|
|
|
version="v$(cat "$(asdf_dir)/version.txt")"
|
2019-11-26 21:02:39 -07:00
|
|
|
if [ -d "$(asdf_dir)/.git" ]; then
|
|
|
|
git_rev="$(git --git-dir "$(asdf_dir)/.git" rev-parse --short HEAD)"
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s-%s\n" "$version" "$git_rev"
|
2019-11-26 21:02:39 -07:00
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version"
|
2019-11-26 21:02:39 -07:00
|
|
|
fi
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
2023-03-26 17:24:16 -07:00
|
|
|
asdf_default_tool_versions_filename() {
|
|
|
|
printf '%s\n' "${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-.tool-versions}"
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
2023-03-26 17:24:16 -07:00
|
|
|
asdf_config_file() {
|
|
|
|
printf '%s\n' "${ASDF_CONFIG_FILE:-$HOME/.asdfrc}"
|
2017-09-06 18:37:08 -07:00
|
|
|
}
|
|
|
|
|
2018-06-10 01:54:39 -07:00
|
|
|
asdf_data_dir() {
|
|
|
|
local data_dir
|
2019-11-29 09:15:38 -07:00
|
|
|
|
2018-12-20 15:25:30 -07:00
|
|
|
if [ -n "${ASDF_DATA_DIR}" ]; then
|
2018-09-16 09:39:21 -07:00
|
|
|
data_dir="${ASDF_DATA_DIR}"
|
2022-06-08 09:54:53 -07:00
|
|
|
elif [ -n "$HOME" ]; then
|
2020-02-05 05:46:24 -07:00
|
|
|
data_dir="$HOME/.asdf"
|
2022-06-08 09:54:53 -07:00
|
|
|
else
|
|
|
|
data_dir=$(asdf_dir)
|
2018-06-10 01:54:39 -07:00
|
|
|
fi
|
|
|
|
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$data_dir"
|
2018-06-10 01:54:39 -07:00
|
|
|
}
|
|
|
|
|
2023-03-26 17:24:16 -07:00
|
|
|
asdf_dir() {
|
|
|
|
if [ -z "$ASDF_DIR" ]; then
|
|
|
|
local current_script_path=${BASH_SOURCE[0]}
|
|
|
|
printf '%s\n' "$(
|
|
|
|
cd -- "$(dirname "$(dirname "$current_script_path")")" || exit
|
|
|
|
printf '%s\n' "$PWD"
|
|
|
|
)"
|
|
|
|
else
|
|
|
|
printf '%s\n' "$ASDF_DIR"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
asdf_repository_url() {
|
|
|
|
printf "https://github.com/asdf-vm/asdf-plugins.git\n"
|
|
|
|
}
|
|
|
|
|
2014-12-13 09:26:56 -07:00
|
|
|
get_install_path() {
|
2015-05-29 09:24:31 -07:00
|
|
|
local plugin=$1
|
2014-12-13 09:26:56 -07:00
|
|
|
local install_type=$2
|
|
|
|
local version=$3
|
2018-06-10 01:54:39 -07:00
|
|
|
|
|
|
|
local install_dir
|
|
|
|
install_dir="$(asdf_data_dir)/installs"
|
|
|
|
|
|
|
|
mkdir -p "${install_dir}/${plugin}"
|
2014-12-13 09:26:56 -07:00
|
|
|
|
2017-08-31 20:21:09 -07:00
|
|
|
if [ "$install_type" = "version" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s/%s/%s\n" "$install_dir" "$plugin" "$version"
|
2020-02-07 20:01:07 -07:00
|
|
|
elif [ "$install_type" = "path" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version"
|
2014-12-14 01:13:43 -07:00
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s/%s/%s-%s\n" "$install_dir" "$plugin" "$install_type" "$version"
|
2014-12-14 01:13:43 -07:00
|
|
|
fi
|
2014-12-13 09:26:56 -07:00
|
|
|
}
|
|
|
|
|
2020-03-06 16:54:33 -07:00
|
|
|
get_download_path() {
|
|
|
|
local plugin=$1
|
|
|
|
local install_type=$2
|
|
|
|
local version=$3
|
|
|
|
|
|
|
|
local download_dir
|
|
|
|
download_dir="$(asdf_data_dir)/downloads"
|
|
|
|
|
|
|
|
mkdir -p "${download_dir}/${plugin}"
|
|
|
|
|
|
|
|
if [ "$install_type" = "version" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s/%s/%s\n" "$download_dir" "$plugin" "$version"
|
2020-03-06 16:54:33 -07:00
|
|
|
elif [ "$install_type" = "path" ]; then
|
|
|
|
return
|
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s/%s/%s-%s\n" "$download_dir" "$plugin" "$install_type" "$version"
|
2020-03-06 16:54:33 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-10 12:54:22 -07:00
|
|
|
list_installed_versions() {
|
|
|
|
local plugin_name=$1
|
2017-09-03 09:11:20 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
2016-12-10 12:54:22 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local plugin_installs_path
|
2018-09-16 09:39:21 -07:00
|
|
|
plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}"
|
2016-12-10 12:54:22 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
if [ -d "$plugin_installs_path" ]; then
|
2019-05-17 18:12:41 -07:00
|
|
|
for install in "${plugin_installs_path}"/*/; do
|
|
|
|
[[ -e "$install" ]] || break
|
2018-09-27 12:26:35 -07:00
|
|
|
basename "$install" | sed 's/^ref-/ref:/'
|
2016-12-10 12:54:22 -07:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-05-17 11:20:51 -07:00
|
|
|
check_if_plugin_exists() {
|
2018-04-30 09:49:40 -07:00
|
|
|
local plugin_name=$1
|
|
|
|
|
2016-07-05 16:19:15 -07:00
|
|
|
# Check if we have a non-empty argument
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ -z "${1}" ]; then
|
2016-07-05 23:32:57 -07:00
|
|
|
display_error "No plugin given"
|
2016-07-05 16:19:15 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-06-10 01:54:39 -07:00
|
|
|
if [ ! -d "$(asdf_data_dir)/plugins/$plugin_name" ]; then
|
2018-04-30 09:49:40 -07:00
|
|
|
display_error "No such plugin: $plugin_name"
|
2014-11-29 09:28:11 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-24 08:11:33 -07:00
|
|
|
check_if_version_exists() {
|
2016-07-05 23:32:57 -07:00
|
|
|
local plugin_name=$1
|
2016-04-24 08:11:33 -07:00
|
|
|
local version=$2
|
2016-12-18 23:25:29 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
check_if_plugin_exists "$plugin_name"
|
2016-07-05 23:32:57 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local install_path
|
|
|
|
install_path=$(find_install_path "$plugin_name" "$version")
|
2017-07-29 10:47:21 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
if [ "$version" != "system" ] && [ ! -d "$install_path" ]; then
|
2016-04-24 08:11:33 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-08-28 16:09:22 -07:00
|
|
|
version_not_installed_text() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local version=$2
|
|
|
|
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "version %s is not installed for %s\n" "$version" "$plugin_name"
|
2020-08-28 16:09:22 -07:00
|
|
|
}
|
|
|
|
|
2015-05-17 11:20:51 -07:00
|
|
|
get_plugin_path() {
|
2022-12-19 06:08:38 -07:00
|
|
|
if [ -n "$1" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$(asdf_data_dir)/plugins/$1"
|
2019-11-30 13:08:52 -07:00
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$(asdf_data_dir)/plugins"
|
2019-11-30 13:08:52 -07:00
|
|
|
fi
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
display_error() {
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$1" >&2
|
2014-11-29 09:28:11 -07:00
|
|
|
}
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2016-10-29 04:08:54 -07:00
|
|
|
get_version_in_dir() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local search_path=$2
|
|
|
|
local legacy_filenames=$3
|
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local asdf_version
|
2022-05-27 04:50:04 -07:00
|
|
|
|
2023-03-26 17:24:16 -07:00
|
|
|
file_name=$(asdf_default_tool_versions_filename)
|
2022-05-27 04:50:04 -07:00
|
|
|
asdf_version=$(parse_asdf_version_file "$search_path/$file_name" "$plugin_name")
|
2016-10-29 04:08:54 -07:00
|
|
|
|
|
|
|
if [ -n "$asdf_version" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$asdf_version|$search_path/$file_name"
|
2016-10-29 04:08:54 -07:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for filename in $legacy_filenames; do
|
2017-09-03 09:11:20 -07:00
|
|
|
local legacy_version
|
2018-09-27 12:26:35 -07:00
|
|
|
legacy_version=$(parse_legacy_version_file "$search_path/$filename" "$plugin_name")
|
2016-10-29 04:08:54 -07:00
|
|
|
|
|
|
|
if [ -n "$legacy_version" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$legacy_version|$search_path/$filename"
|
2016-10-29 04:08:54 -07:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-10-22 16:03:05 -07:00
|
|
|
find_versions() {
|
2016-07-24 17:12:40 -07:00
|
|
|
local plugin_name=$1
|
2016-08-27 21:15:56 -07:00
|
|
|
local search_path=$2
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local version
|
|
|
|
version=$(get_version_from_env "$plugin_name")
|
2016-11-10 12:01:19 -07:00
|
|
|
if [ -n "$version" ]; then
|
2018-02-24 23:11:16 -07:00
|
|
|
local upcase_name
|
2022-12-23 02:53:22 -07:00
|
|
|
upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_')
|
2018-02-24 23:11:16 -07:00
|
|
|
local version_env_var="ASDF_${upcase_name}_VERSION"
|
|
|
|
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version|$version_env_var environment variable"
|
2016-11-10 12:01:19 -07:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
local legacy_config
|
|
|
|
legacy_config=$(get_asdf_config_value "legacy_version_file")
|
|
|
|
local legacy_list_filenames_script
|
|
|
|
legacy_list_filenames_script="${plugin_path}/bin/list-legacy-filenames"
|
2016-08-27 21:15:56 -07:00
|
|
|
local legacy_filenames=""
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
if [ "$legacy_config" = "yes" ] && [ -f "$legacy_list_filenames_script" ]; then
|
2023-03-24 05:37:23 -07:00
|
|
|
legacy_filenames=$("$legacy_list_filenames_script")
|
2016-07-24 17:12:40 -07:00
|
|
|
fi
|
2015-05-14 21:36:21 -07:00
|
|
|
|
|
|
|
while [ "$search_path" != "/" ]; do
|
2016-11-10 12:01:19 -07:00
|
|
|
version=$(get_version_in_dir "$plugin_name" "$search_path" "$legacy_filenames")
|
2016-10-29 04:08:54 -07:00
|
|
|
if [ -n "$version" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version"
|
2016-08-27 21:15:56 -07:00
|
|
|
return 0
|
|
|
|
fi
|
2015-12-22 17:00:18 -07:00
|
|
|
search_path=$(dirname "$search_path")
|
2015-05-14 21:36:21 -07:00
|
|
|
done
|
2016-10-29 04:08:54 -07:00
|
|
|
|
|
|
|
get_version_in_dir "$plugin_name" "$HOME" "$legacy_filenames"
|
2017-09-14 04:21:36 -07:00
|
|
|
|
|
|
|
if [ -f "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]; then
|
2019-10-22 16:03:05 -07:00
|
|
|
versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name")
|
|
|
|
if [ -n "$versions" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
|
2017-09-14 04:21:36 -07:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
2015-05-14 03:13:04 -07:00
|
|
|
}
|
|
|
|
|
2018-02-25 15:42:33 -07:00
|
|
|
display_no_version_set() {
|
|
|
|
local plugin_name=$1
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "No version is set for %s; please run \`asdf <global | shell | local> %s <version>\`\n" "$plugin_name" "$plugin_name"
|
2018-02-25 15:42:33 -07:00
|
|
|
}
|
|
|
|
|
2016-11-10 12:01:19 -07:00
|
|
|
get_version_from_env() {
|
|
|
|
local plugin_name=$1
|
2017-09-03 09:11:20 -07:00
|
|
|
local upcase_name
|
2022-12-23 02:53:22 -07:00
|
|
|
upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_')
|
2016-11-10 12:01:19 -07:00
|
|
|
local version_env_var="ASDF_${upcase_name}_VERSION"
|
2020-03-07 05:18:46 -07:00
|
|
|
local version=${!version_env_var:-}
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version"
|
2016-11-10 12:01:19 -07:00
|
|
|
}
|
|
|
|
|
2016-07-01 02:25:34 -07:00
|
|
|
find_install_path() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local version=$2
|
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
# shellcheck disable=SC2162
|
2016-07-01 02:25:34 -07:00
|
|
|
IFS=':' read -a version_info <<<"$version"
|
|
|
|
|
2017-09-03 20:20:35 -07:00
|
|
|
if [ "$version" = "system" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "\n"
|
2016-07-01 02:25:34 -07:00
|
|
|
elif [ "${version_info[0]}" = "ref" ]; then
|
|
|
|
local install_type="${version_info[0]}"
|
|
|
|
local version="${version_info[1]}"
|
2017-09-03 09:11:20 -07:00
|
|
|
get_install_path "$plugin_name" "$install_type" "$version"
|
2016-07-01 02:25:34 -07:00
|
|
|
elif [ "${version_info[0]}" = "path" ]; then
|
|
|
|
# This is for people who have the local source already compiled
|
|
|
|
# Like those who work on the language, etc
|
|
|
|
# We'll allow specifying path:/foo/bar/project in .tool-versions
|
|
|
|
# And then use the binaries there
|
|
|
|
local install_type="path"
|
|
|
|
local version="path"
|
2023-01-06 05:08:48 -07:00
|
|
|
|
|
|
|
util_resolve_user_path "${version_info[1]}"
|
|
|
|
printf "%s\n" "${util_resolve_user_path_reply}"
|
2016-07-01 02:25:34 -07:00
|
|
|
else
|
|
|
|
local install_type="version"
|
|
|
|
local version="${version_info[0]}"
|
2017-09-03 09:11:20 -07:00
|
|
|
get_install_path "$plugin_name" "$install_type" "$version"
|
2016-07-01 02:25:34 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-05 08:23:41 -07:00
|
|
|
get_custom_executable_path() {
|
|
|
|
local plugin_path=$1
|
|
|
|
local install_path=$2
|
|
|
|
local executable_path=$3
|
|
|
|
|
|
|
|
# custom plugin hook for executable path
|
2019-01-19 03:12:52 -07:00
|
|
|
if [ -x "${plugin_path}/bin/exec-path" ]; then
|
2019-01-05 08:23:41 -07:00
|
|
|
cmd=$(basename "$executable_path")
|
2019-01-20 13:02:22 -07:00
|
|
|
local relative_path
|
|
|
|
# shellcheck disable=SC2001
|
2022-12-23 02:53:22 -07:00
|
|
|
relative_path=$(printf "%s\n" "$executable_path" | sed -e "s|${install_path}/||")
|
2019-01-20 13:02:22 -07:00
|
|
|
relative_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$relative_path")"
|
|
|
|
executable_path="$install_path/$relative_path"
|
2019-01-05 08:23:41 -07:00
|
|
|
fi
|
|
|
|
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$executable_path"
|
2019-01-05 08:23:41 -07:00
|
|
|
}
|
|
|
|
|
2016-07-01 02:25:34 -07:00
|
|
|
get_executable_path() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local version=$2
|
|
|
|
local executable_path=$3
|
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
check_if_version_exists "$plugin_name" "$version"
|
2016-07-05 23:32:57 -07:00
|
|
|
|
2017-09-03 20:20:35 -07:00
|
|
|
if [ "$version" = "system" ]; then
|
2021-11-15 01:03:53 -07:00
|
|
|
path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims")
|
2017-09-03 09:11:20 -07:00
|
|
|
cmd=$(basename "$executable_path")
|
2018-06-16 12:04:38 -07:00
|
|
|
cmd_path=$(PATH=$path command -v "$cmd" 2>&1)
|
2018-09-27 12:26:35 -07:00
|
|
|
# shellcheck disable=SC2181
|
2016-07-01 02:25:34 -07:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$cmd_path"
|
2016-07-01 02:25:34 -07:00
|
|
|
else
|
2017-09-03 09:11:20 -07:00
|
|
|
local install_path
|
2018-09-27 12:26:35 -07:00
|
|
|
install_path=$(find_install_path "$plugin_name" "$version")
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "${install_path}"/"${executable_path}"
|
2016-07-01 02:25:34 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-07-24 17:12:40 -07:00
|
|
|
parse_asdf_version_file() {
|
|
|
|
local file_path=$1
|
|
|
|
local plugin_name=$2
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2016-10-27 00:24:34 -07:00
|
|
|
if [ -f "$file_path" ]; then
|
2017-09-03 09:11:20 -07:00
|
|
|
local version
|
2019-03-31 12:39:36 -07:00
|
|
|
version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //")
|
2023-01-06 05:08:48 -07:00
|
|
|
|
2016-11-11 22:30:13 -07:00
|
|
|
if [ -n "$version" ]; then
|
2023-01-06 05:08:48 -07:00
|
|
|
if [[ "$version" == path:* ]]; then
|
|
|
|
util_resolve_user_path "${version#path:}"
|
|
|
|
printf "%s\n" "path:${util_resolve_user_path_reply}"
|
|
|
|
else
|
|
|
|
printf "%s\n" "$version"
|
|
|
|
fi
|
|
|
|
|
2016-11-11 22:30:13 -07:00
|
|
|
return 0
|
|
|
|
fi
|
2016-08-27 21:15:56 -07:00
|
|
|
fi
|
2015-06-24 06:46:49 -07:00
|
|
|
}
|
|
|
|
|
2016-07-24 17:12:40 -07:00
|
|
|
parse_legacy_version_file() {
|
|
|
|
local file_path=$1
|
|
|
|
local plugin_name=$2
|
2015-06-24 06:46:49 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
local parse_legacy_script
|
|
|
|
parse_legacy_script="${plugin_path}/bin/parse-legacy-file"
|
2015-05-14 03:13:04 -07:00
|
|
|
|
2017-09-02 20:05:40 -07:00
|
|
|
if [ -f "$file_path" ]; then
|
2017-09-03 09:11:20 -07:00
|
|
|
if [ -f "$parse_legacy_script" ]; then
|
2021-07-29 15:44:14 -07:00
|
|
|
"$parse_legacy_script" "$file_path"
|
2016-08-27 21:15:56 -07:00
|
|
|
else
|
2017-09-03 09:11:20 -07:00
|
|
|
cat "$file_path"
|
2016-08-27 21:15:56 -07:00
|
|
|
fi
|
2015-11-28 15:27:54 -07:00
|
|
|
fi
|
|
|
|
}
|
2016-04-24 16:18:12 -07:00
|
|
|
|
2016-07-24 17:12:40 -07:00
|
|
|
get_preset_version_for() {
|
|
|
|
local plugin_name=$1
|
2017-09-03 09:11:20 -07:00
|
|
|
local search_path
|
2022-12-27 06:33:59 -07:00
|
|
|
search_path=$PWD
|
2017-09-03 09:11:20 -07:00
|
|
|
local version_and_path
|
2019-10-22 16:03:05 -07:00
|
|
|
version_and_path=$(find_versions "$plugin_name" "$search_path")
|
2017-09-03 09:11:20 -07:00
|
|
|
local version
|
|
|
|
version=$(cut -d '|' -f 1 <<<"$version_and_path")
|
2016-08-27 21:15:56 -07:00
|
|
|
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$version"
|
2016-07-24 17:12:40 -07:00
|
|
|
}
|
2016-04-24 16:18:12 -07:00
|
|
|
|
2016-04-24 06:20:05 -07:00
|
|
|
get_asdf_config_value_from_file() {
|
2016-07-05 23:32:57 -07:00
|
|
|
local config_path=$1
|
|
|
|
local key=$2
|
2016-04-24 06:20:05 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
if [ ! -f "$config_path" ]; then
|
2019-01-20 13:02:22 -07:00
|
|
|
return 1
|
2016-07-05 23:32:57 -07:00
|
|
|
fi
|
2016-04-24 06:20:05 -07:00
|
|
|
|
2017-09-03 09:11:20 -07:00
|
|
|
local result
|
2022-12-20 13:54:00 -07:00
|
|
|
result=$(grep -E "^\s*$key\s*=\s*" "$config_path" | head | sed -e 's/^[^=]*= *//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
2016-07-05 23:32:57 -07:00
|
|
|
if [ -n "$result" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$result"
|
2019-01-20 13:02:22 -07:00
|
|
|
return 0
|
2016-07-05 23:32:57 -07:00
|
|
|
fi
|
2019-01-20 13:02:22 -07:00
|
|
|
|
|
|
|
return 2
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
get_asdf_config_value() {
|
2016-07-05 23:32:57 -07:00
|
|
|
local key=$1
|
2023-03-26 17:24:16 -07:00
|
|
|
local config_path=
|
|
|
|
config_path=$(asdf_config_file)
|
2018-02-27 12:56:04 -07:00
|
|
|
local default_config_path=${ASDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}
|
2016-04-24 06:20:05 -07:00
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
local local_config_path
|
|
|
|
local_config_path="$(find_file_upwards ".asdfrc")"
|
2016-04-24 06:20:05 -07:00
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
get_asdf_config_value_from_file "$local_config_path" "$key" ||
|
|
|
|
get_asdf_config_value_from_file "$config_path" "$key" ||
|
2017-09-03 09:11:20 -07:00
|
|
|
get_asdf_config_value_from_file "$default_config_path" "$key"
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
2017-03-26 16:44:22 -07:00
|
|
|
|
2021-08-03 15:41:19 -07:00
|
|
|
# Whether the plugin shortname repo needs to be synced
|
|
|
|
# 0: if no sync needs to occur
|
|
|
|
# 1: if sync needs to occur
|
2017-08-24 19:29:23 -07:00
|
|
|
repository_needs_update() {
|
2021-06-01 21:22:27 -07:00
|
|
|
local plugin_repository_last_check_duration
|
2021-08-03 15:41:19 -07:00
|
|
|
local sync_required
|
|
|
|
|
2021-06-01 21:22:27 -07:00
|
|
|
plugin_repository_last_check_duration="$(get_asdf_config_value "plugin_repository_last_check_duration")"
|
2021-08-03 15:41:19 -07:00
|
|
|
|
|
|
|
if [ "never" != "$plugin_repository_last_check_duration" ]; then
|
|
|
|
local update_file_dir
|
|
|
|
local update_file_name
|
|
|
|
update_file_dir="$(asdf_data_dir)/tmp"
|
|
|
|
update_file_name="repo-updated"
|
|
|
|
# `find` outputs filename if it has not been modified in plugin_repository_last_check_duration setting.
|
|
|
|
sync_required=$(find "$update_file_dir" -name "$update_file_name" -type f -mmin +"${plugin_repository_last_check_duration:-60}" -print)
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ "$sync_required" ]
|
2017-08-24 19:29:23 -07:00
|
|
|
}
|
|
|
|
|
2017-03-26 16:44:22 -07:00
|
|
|
initialize_or_update_repository() {
|
2017-04-19 20:37:03 -07:00
|
|
|
local repository_url
|
|
|
|
local repository_path
|
2017-03-26 16:44:22 -07:00
|
|
|
|
2022-06-27 16:47:49 -07:00
|
|
|
disable_plugin_short_name_repo="$(get_asdf_config_value "disable_plugin_short_name_repository")"
|
|
|
|
if [ "yes" = "$disable_plugin_short_name_repo" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Short-name plugin repository is disabled\n" >&2
|
2022-06-27 16:47:49 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-04-19 20:37:03 -07:00
|
|
|
repository_url=$(asdf_repository_url)
|
2018-06-10 01:54:39 -07:00
|
|
|
repository_path=$(asdf_data_dir)/repository
|
2017-04-19 20:37:03 -07:00
|
|
|
|
2017-08-24 19:29:23 -07:00
|
|
|
if [ ! -d "$repository_path" ]; then
|
2020-09-21 15:27:52 -07:00
|
|
|
printf "initializing plugin repository..."
|
2017-04-19 20:37:03 -07:00
|
|
|
git clone "$repository_url" "$repository_path"
|
2017-08-24 19:29:23 -07:00
|
|
|
elif repository_needs_update; then
|
2020-09-21 15:27:52 -07:00
|
|
|
printf "updating plugin repository..."
|
2017-08-24 19:29:23 -07:00
|
|
|
(cd "$repository_path" && git fetch && git reset --hard origin/master)
|
2017-03-26 16:44:22 -07:00
|
|
|
fi
|
2017-08-24 19:29:23 -07:00
|
|
|
|
2018-06-10 01:54:39 -07:00
|
|
|
mkdir -p "$(asdf_data_dir)/tmp"
|
|
|
|
touch "$(asdf_data_dir)/tmp/repo-updated"
|
2017-03-26 16:44:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
get_plugin_source_url() {
|
2017-04-19 20:40:06 -07:00
|
|
|
local plugin_name=$1
|
2017-04-19 20:37:03 -07:00
|
|
|
local plugin_config
|
|
|
|
|
2018-06-10 01:54:39 -07:00
|
|
|
plugin_config="$(asdf_data_dir)/repository/plugins/$plugin_name"
|
2017-04-19 20:37:03 -07:00
|
|
|
|
|
|
|
if [ -f "$plugin_config" ]; then
|
|
|
|
grep "repository" "$plugin_config" | awk -F'=' '{print $2}' | sed 's/ //'
|
2017-03-26 16:44:22 -07:00
|
|
|
fi
|
|
|
|
}
|
2017-10-10 10:02:42 -07:00
|
|
|
|
|
|
|
find_tool_versions() {
|
2023-03-26 17:24:16 -07:00
|
|
|
find_file_upwards "$(asdf_default_tool_versions_filename)"
|
2019-01-20 13:02:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
find_file_upwards() {
|
|
|
|
local name="$1"
|
2018-09-27 12:26:35 -07:00
|
|
|
local search_path
|
2022-12-27 06:33:59 -07:00
|
|
|
search_path=$PWD
|
2018-09-27 12:26:35 -07:00
|
|
|
while [ "$search_path" != "/" ]; do
|
2019-01-20 13:02:22 -07:00
|
|
|
if [ -f "$search_path/$name" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "${search_path}/$name"
|
2018-09-27 12:26:35 -07:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
search_path=$(dirname "$search_path")
|
|
|
|
done
|
2017-10-10 10:02:42 -07:00
|
|
|
}
|
2018-06-16 19:59:37 -07:00
|
|
|
|
|
|
|
resolve_symlink() {
|
2018-09-27 12:26:35 -07:00
|
|
|
local symlink
|
|
|
|
symlink="$1"
|
2018-06-16 19:59:37 -07:00
|
|
|
|
2018-09-27 12:26:35 -07:00
|
|
|
# This seems to be the only cross-platform way to resolve symlink paths to
|
|
|
|
# the real file path.
|
|
|
|
# shellcheck disable=SC2012
|
2021-12-29 10:10:39 -07:00
|
|
|
resolved_path=$(ls -l "$symlink" | sed -e 's|.*-> \(.*\)|\1|') # asdf_allow: ls '
|
2018-10-07 17:36:29 -07:00
|
|
|
|
|
|
|
# Check if resolved path is relative or not by looking at the first character.
|
|
|
|
# If it is a slash we can assume it's root and absolute. Otherwise we treat it
|
|
|
|
# as relative
|
2018-10-07 18:33:45 -07:00
|
|
|
case $resolved_path in
|
2020-06-29 16:16:35 -07:00
|
|
|
/*)
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$resolved_path"
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
|
|
|
*)
|
2020-10-08 06:59:50 -07:00
|
|
|
(
|
|
|
|
cd "$(dirname "$symlink")" || exit 1
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$PWD/$resolved_path"
|
2020-10-08 06:59:50 -07:00
|
|
|
)
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
2018-10-07 18:33:45 -07:00
|
|
|
esac
|
2018-06-16 19:59:37 -07:00
|
|
|
}
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
list_plugin_bin_paths() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local version=$2
|
|
|
|
local install_type=$3
|
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
local install_path
|
|
|
|
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
|
|
|
|
|
|
|
|
if [ -f "${plugin_path}/bin/list-bin-paths" ]; then
|
|
|
|
local space_separated_list_of_bin_paths
|
|
|
|
|
|
|
|
# shellcheck disable=SC2030
|
|
|
|
space_separated_list_of_bin_paths=$(
|
|
|
|
export ASDF_INSTALL_TYPE=$install_type
|
|
|
|
export ASDF_INSTALL_VERSION=$version
|
|
|
|
export ASDF_INSTALL_PATH=$install_path
|
2021-07-29 15:44:14 -07:00
|
|
|
"${plugin_path}/bin/list-bin-paths"
|
2019-01-19 03:12:52 -07:00
|
|
|
)
|
|
|
|
else
|
|
|
|
local space_separated_list_of_bin_paths="bin"
|
|
|
|
fi
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$space_separated_list_of_bin_paths"
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
list_plugin_exec_paths() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local full_version=$2
|
|
|
|
check_if_plugin_exists "$plugin_name"
|
|
|
|
|
|
|
|
IFS=':' read -r -a version_info <<<"$full_version"
|
|
|
|
if [ "${version_info[0]}" = "ref" ]; then
|
|
|
|
local install_type="${version_info[0]}"
|
|
|
|
local version="${version_info[1]}"
|
2020-02-07 20:01:07 -07:00
|
|
|
elif [ "${version_info[0]}" = "path" ]; then
|
|
|
|
local install_type="${version_info[0]}"
|
|
|
|
local version="${version_info[1]}"
|
2019-01-19 03:12:52 -07:00
|
|
|
else
|
|
|
|
local install_type="version"
|
|
|
|
local version="${version_info[0]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
local plugin_shims_path
|
|
|
|
plugin_shims_path=$(get_plugin_path "$plugin_name")/shims
|
|
|
|
if [ -d "$plugin_shims_path" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$plugin_shims_path"
|
2019-01-19 03:12:52 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
space_separated_list_of_bin_paths="$(list_plugin_bin_paths "$plugin_name" "$version" "$install_type")"
|
|
|
|
IFS=' ' read -r -a all_bin_paths <<<"$space_separated_list_of_bin_paths"
|
|
|
|
|
|
|
|
local install_path
|
|
|
|
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
|
|
|
|
|
|
|
|
for bin_path in "${all_bin_paths[@]}"; do
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$install_path/$bin_path"
|
2019-01-19 03:12:52 -07:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-01-21 00:33:52 -07:00
|
|
|
with_plugin_env() {
|
2019-01-19 03:12:52 -07:00
|
|
|
local plugin_name=$1
|
2019-01-21 00:33:52 -07:00
|
|
|
local full_version=$2
|
|
|
|
local callback=$3
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2019-01-21 00:33:52 -07:00
|
|
|
IFS=':' read -r -a version_info <<<"$full_version"
|
|
|
|
if [ "${version_info[0]}" = "ref" ]; then
|
|
|
|
local install_type="${version_info[0]}"
|
|
|
|
local version="${version_info[1]}"
|
|
|
|
else
|
|
|
|
local install_type="version"
|
|
|
|
local version="${version_info[0]}"
|
|
|
|
fi
|
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
if [ "$version" = "system" ]; then
|
|
|
|
# execute as is for system
|
|
|
|
"$callback"
|
|
|
|
return $?
|
|
|
|
fi
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
# add the plugin listed exec paths to PATH
|
2019-08-14 17:21:57 -07:00
|
|
|
local path exec_paths
|
|
|
|
exec_paths="$(list_plugin_exec_paths "$plugin_name" "$full_version")"
|
|
|
|
|
|
|
|
# exec_paths contains a trailing newline which is converted to a colon, so no
|
|
|
|
# colon is needed between the subshell and the PATH variable in this string
|
2020-09-21 15:27:52 -07:00
|
|
|
path="$(tr '\n' ':' <<<"$exec_paths")$PATH"
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
# If no custom exec-env transform, just execute callback
|
|
|
|
if [ ! -f "${plugin_path}/bin/exec-env" ]; then
|
|
|
|
PATH=$path "$callback"
|
|
|
|
return $?
|
|
|
|
fi
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
# Load the plugin custom environment
|
|
|
|
local install_path
|
|
|
|
install_path=$(find_install_path "$plugin_name" "$full_version")
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
ASDF_INSTALL_TYPE=$install_type \
|
|
|
|
ASDF_INSTALL_VERSION=$version \
|
|
|
|
ASDF_INSTALL_PATH=$install_path \
|
2021-05-21 09:03:06 -07:00
|
|
|
. "${plugin_path}/bin/exec-env"
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2019-03-26 10:36:08 -07:00
|
|
|
PATH=$path "$callback"
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin_executables() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local full_version=$2
|
2021-07-19 21:21:39 -07:00
|
|
|
local all_bin_paths
|
|
|
|
IFS=$'\n' read -rd '' -a all_bin_paths <<<"$(list_plugin_exec_paths "$plugin_name" "$full_version")"
|
|
|
|
for bin_path in "${all_bin_paths[@]}"; do
|
2019-01-19 03:12:52 -07:00
|
|
|
for executable_file in "$bin_path"/*; do
|
|
|
|
if is_executable "$executable_file"; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$executable_file"
|
2019-01-19 03:12:52 -07:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
is_executable() {
|
|
|
|
local executable_path=$1
|
|
|
|
if [[ (-f "$executable_path") && (-x "$executable_path") ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin_shims() {
|
|
|
|
local plugin_name=$1
|
|
|
|
local full_version=$2
|
2019-05-17 11:21:52 -07:00
|
|
|
grep -lx "# asdf-plugin: $plugin_name $full_version" "$(asdf_data_dir)/shims"/* 2>/dev/null
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
shim_plugin_versions() {
|
|
|
|
local executable_name
|
|
|
|
executable_name=$(basename "$1")
|
|
|
|
local shim_path
|
|
|
|
shim_path="$(asdf_data_dir)/shims/${executable_name}"
|
|
|
|
if [ -x "$shim_path" ]; then
|
2019-03-23 14:21:55 -07:00
|
|
|
grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | uniq
|
2019-01-19 03:12:52 -07:00
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "asdf: unknown shim %s\n" "$executable_name"
|
2019-01-19 03:12:52 -07:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-12-20 10:26:00 -07:00
|
|
|
shim_plugins() {
|
|
|
|
local executable_name
|
|
|
|
executable_name=$(basename "$1")
|
|
|
|
local shim_path
|
|
|
|
shim_path="$(asdf_data_dir)/shims/${executable_name}"
|
|
|
|
if [ -x "$shim_path" ]; then
|
|
|
|
grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | cut -d' ' -f 1 | uniq
|
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "asdf: unknown shim %s\n" "$executable_name"
|
2019-12-20 10:26:00 -07:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-25 21:11:45 -07:00
|
|
|
strip_tool_version_comments() {
|
|
|
|
local tool_version_path="$1"
|
2022-04-08 07:44:07 -07:00
|
|
|
# Use sed to strip comments from the tool version file
|
|
|
|
# Breakdown of sed command:
|
2022-07-05 06:40:33 -07:00
|
|
|
# This command represents 3 steps, separated by a semi-colon (;), that run on each line.
|
2022-04-08 07:44:07 -07:00
|
|
|
# 1. Delete line if it starts with any blankspace and a #.
|
|
|
|
# 2. Find a # and delete it and everything after the #.
|
|
|
|
# 3. Remove any whitespace from the end of the line.
|
|
|
|
# Finally, the command will print the lines that are not empty.
|
|
|
|
sed '/^[[:blank:]]*#/d;s/#.*//;s/[[:blank:]]*$//' "$tool_version_path"
|
2019-03-25 21:11:45 -07:00
|
|
|
}
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2019-01-19 12:00:33 -07:00
|
|
|
asdf_run_hook() {
|
|
|
|
local hook_name=$1
|
|
|
|
local hook_cmd
|
|
|
|
hook_cmd="$(get_asdf_config_value "$hook_name")"
|
|
|
|
if [ -n "$hook_cmd" ]; then
|
|
|
|
asdf_hook_fun() {
|
|
|
|
unset asdf_hook_fun
|
|
|
|
ev'al' "$hook_cmd" # ignore banned command just here
|
|
|
|
}
|
|
|
|
asdf_hook_fun "${@:2}"
|
|
|
|
fi
|
|
|
|
}
|
2019-01-20 13:02:22 -07:00
|
|
|
|
2020-02-07 15:21:37 -07:00
|
|
|
get_shim_versions() {
|
|
|
|
shim_name=$1
|
|
|
|
shim_plugin_versions "${shim_name}"
|
|
|
|
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | awk '{print$1" system"}'
|
|
|
|
}
|
|
|
|
|
|
|
|
preset_versions() {
|
|
|
|
shim_name=$1
|
2022-12-23 02:53:22 -07:00
|
|
|
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c ". $(asdf_dir)/lib/utils.bash; printf \"%s %s\n\" PLUGIN \$(get_preset_version_for PLUGIN)"
|
2020-02-07 15:21:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
select_from_preset_version() {
|
2021-02-05 09:26:02 -07:00
|
|
|
local shim_name=$1
|
2021-04-27 01:04:28 -07:00
|
|
|
local shim_versions
|
2021-04-27 02:28:57 -07:00
|
|
|
local preset_versions
|
2021-04-27 01:04:28 -07:00
|
|
|
|
2021-04-27 02:28:57 -07:00
|
|
|
shim_versions=$(get_shim_versions "$shim_name")
|
|
|
|
if [ -n "$shim_versions" ]; then
|
|
|
|
preset_versions=$(preset_versions "$shim_name")
|
2022-12-23 02:53:22 -07:00
|
|
|
grep -F "$shim_versions" <<<"$preset_versions" | head -n 1 | xargs -IVERSION printf "%s\n" VERSION
|
2021-04-27 02:28:57 -07:00
|
|
|
fi
|
2020-02-07 15:21:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
select_version() {
|
|
|
|
shim_name=$1
|
|
|
|
# First, we get the all the plugins where the
|
|
|
|
# current shim is available.
|
|
|
|
# Then, we iterate on all versions set for each plugin
|
|
|
|
# Note that multiple plugin versions can be set for a single plugin.
|
|
|
|
# These are separated by a space. e.g. python 3.7.2 2.7.15
|
|
|
|
# For each plugin/version pair, we check if it is present in the shim
|
|
|
|
local search_path
|
2022-12-27 06:33:59 -07:00
|
|
|
search_path=$PWD
|
2020-02-07 15:21:37 -07:00
|
|
|
local shim_versions
|
|
|
|
IFS=$'\n' read -rd '' -a shim_versions <<<"$(get_shim_versions "$shim_name")"
|
|
|
|
|
|
|
|
local plugins
|
|
|
|
IFS=$'\n' read -rd '' -a plugins <<<"$(shim_plugins "$shim_name")"
|
|
|
|
|
|
|
|
for plugin_name in "${plugins[@]}"; do
|
|
|
|
local version_and_path
|
|
|
|
local version_string
|
|
|
|
local usable_plugin_versions
|
|
|
|
local _path
|
|
|
|
version_and_path=$(find_versions "$plugin_name" "$search_path")
|
|
|
|
IFS='|' read -r version_string _path <<<"$version_and_path"
|
|
|
|
IFS=' ' read -r -a usable_plugin_versions <<<"$version_string"
|
|
|
|
for plugin_version in "${usable_plugin_versions[@]}"; do
|
|
|
|
for plugin_and_version in "${shim_versions[@]}"; do
|
|
|
|
local plugin_shim_name
|
|
|
|
local plugin_shim_version
|
|
|
|
IFS=' ' read -r plugin_shim_name plugin_shim_version <<<"$plugin_and_version"
|
2020-02-07 20:01:07 -07:00
|
|
|
if [[ "$plugin_name" == "$plugin_shim_name" ]]; then
|
|
|
|
if [[ "$plugin_version" == "$plugin_shim_version" ]]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$plugin_name $plugin_version"
|
2020-02-07 20:01:07 -07:00
|
|
|
return
|
|
|
|
elif [[ "$plugin_version" == "path:"* ]]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s\n" "$plugin_name $plugin_version"
|
2020-02-07 20:01:07 -07:00
|
|
|
return
|
|
|
|
fi
|
2020-02-07 15:21:37 -07:00
|
|
|
fi
|
2019-03-14 13:08:13 -07:00
|
|
|
done
|
|
|
|
done
|
2020-02-07 15:21:37 -07:00
|
|
|
done
|
|
|
|
}
|
2019-01-20 13:02:22 -07:00
|
|
|
|
2020-02-07 15:21:37 -07:00
|
|
|
with_shim_executable() {
|
2019-01-20 13:02:22 -07:00
|
|
|
local shim_name
|
|
|
|
shim_name=$(basename "$1")
|
|
|
|
local shim_exec="${2}"
|
|
|
|
|
|
|
|
if [ ! -f "$(asdf_data_dir)/shims/${shim_name}" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s %s %s\n" "unknown command:" "${shim_name}." "Perhaps you have to reshim?" >&2
|
2019-01-20 13:02:22 -07:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-03-14 13:08:13 -07:00
|
|
|
local selected_version
|
2020-02-07 20:21:08 -07:00
|
|
|
selected_version="$(select_version "$shim_name")"
|
2019-03-14 13:08:13 -07:00
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
if [ -z "$selected_version" ]; then
|
2020-02-07 20:21:08 -07:00
|
|
|
selected_version="$(select_from_preset_version "$shim_name")"
|
2019-01-20 13:02:22 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$selected_version" ]; then
|
2019-03-14 13:08:13 -07:00
|
|
|
local plugin_name
|
|
|
|
local full_version
|
|
|
|
local plugin_path
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2019-03-14 13:08:13 -07:00
|
|
|
IFS=' ' read -r plugin_name full_version <<<"$selected_version"
|
2019-01-20 13:02:22 -07:00
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
|
2022-12-29 13:24:24 -07:00
|
|
|
# This function does get invoked, but shellcheck sees it as unused code
|
|
|
|
# shellcheck disable=SC2317
|
2023-01-28 20:52:22 -07:00
|
|
|
run_within_env() {
|
2019-12-21 13:24:55 -07:00
|
|
|
local path
|
2021-11-15 01:03:53 -07:00
|
|
|
path=$(remove_path_from_path "$PATH" "$(asdf_data_dir)/shims")
|
2019-01-23 21:18:18 -07:00
|
|
|
|
|
|
|
executable_path=$(PATH=$path command -v "$shim_name")
|
2019-01-20 13:02:22 -07:00
|
|
|
|
2019-01-21 00:33:52 -07:00
|
|
|
if [ -x "${plugin_path}/bin/exec-path" ]; then
|
|
|
|
install_path=$(find_install_path "$plugin_name" "$full_version")
|
2019-10-24 09:05:41 -07:00
|
|
|
executable_path=$(get_custom_executable_path "${plugin_path}" "${install_path}" "${executable_path:-${shim_name}}")
|
2019-01-21 00:33:52 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
"$shim_exec" "$plugin_name" "$full_version" "$executable_path"
|
|
|
|
}
|
2019-01-20 13:02:22 -07:00
|
|
|
|
2019-01-21 00:33:52 -07:00
|
|
|
with_plugin_env "$plugin_name" "$full_version" run_within_env
|
2019-01-20 13:02:22 -07:00
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
2019-12-20 10:26:00 -07:00
|
|
|
local preset_plugin_versions
|
|
|
|
preset_plugin_versions=()
|
2020-07-31 01:46:33 -07:00
|
|
|
local closest_tool_version
|
|
|
|
closest_tool_version=$(find_tool_versions)
|
2019-12-04 07:18:58 -07:00
|
|
|
|
2019-12-20 10:26:00 -07:00
|
|
|
local shim_plugins
|
|
|
|
IFS=$'\n' read -rd '' -a shim_plugins <<<"$(shim_plugins "$shim_name")"
|
|
|
|
for shim_plugin in "${shim_plugins[@]}"; do
|
|
|
|
local shim_versions
|
|
|
|
local version_string
|
|
|
|
version_string=$(get_preset_version_for "$shim_plugin")
|
|
|
|
IFS=' ' read -r -a shim_versions <<<"$version_string"
|
|
|
|
local usable_plugin_versions
|
|
|
|
for shim_version in "${shim_versions[@]}"; do
|
|
|
|
preset_plugin_versions+=("$shim_plugin $shim_version")
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "${preset_plugin_versions[*]}" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s %s\n" "No preset version installed for command" "$shim_name"
|
|
|
|
printf "%s\n\n" "Please install a version by running one of the following:"
|
2019-12-20 10:26:00 -07:00
|
|
|
for preset_plugin_version in "${preset_plugin_versions[@]}"; do
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s %s\n" "asdf install" "$preset_plugin_version"
|
2019-12-20 10:26:00 -07:00
|
|
|
done
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
|
2019-12-04 07:18:58 -07:00
|
|
|
else
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "%s %s\n" "No version is set for command" "$shim_name"
|
|
|
|
printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
|
2019-12-04 07:18:58 -07:00
|
|
|
fi
|
2019-01-20 13:02:22 -07:00
|
|
|
shim_plugin_versions "${shim_name}"
|
|
|
|
) >&2
|
2019-12-04 07:18:58 -07:00
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
return 126
|
|
|
|
}
|
2021-11-15 01:03:53 -07:00
|
|
|
|
|
|
|
substitute() {
|
2022-07-05 06:40:33 -07:00
|
|
|
# Use Bash substitution rather than sed as it will handle escaping of all
|
2021-11-15 01:03:53 -07:00
|
|
|
# strings for us.
|
|
|
|
local input=$1
|
|
|
|
local find_str=$2
|
|
|
|
local replace=$3
|
|
|
|
printf "%s" "${input//"$find_str"/"$replace"}"
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_path_from_path() {
|
|
|
|
# A helper function for removing an arbitrary path from the PATH variable.
|
|
|
|
# Output is a new string suitable for assignment to PATH
|
|
|
|
local PATH=$1
|
|
|
|
local path=$2
|
|
|
|
substitute "$PATH" "$path" "" | sed -e "s|::|:|g"
|
|
|
|
}
|
2023-01-06 05:08:48 -07:00
|
|
|
|
|
|
|
# @description Strings that began with a ~ are always paths. In
|
|
|
|
# that case, then ensure ~ it handled like a shell
|
|
|
|
util_resolve_user_path() {
|
|
|
|
util_resolve_user_path_reply=
|
|
|
|
local path="$1"
|
|
|
|
|
|
|
|
# shellcheck disable=SC2088
|
|
|
|
if [ "${path::2}" = '~/' ]; then
|
|
|
|
util_resolve_user_path_reply="${HOME}/${path:2}"
|
|
|
|
else
|
|
|
|
util_resolve_user_path_reply="$path"
|
|
|
|
fi
|
|
|
|
}
|
2023-03-22 18:23:53 -07:00
|
|
|
|
|
|
|
get_plugin_remote_url() {
|
|
|
|
local plugin_name="$1"
|
|
|
|
local plugin_path
|
|
|
|
plugin_path="$(get_plugin_path "$plugin_name")"
|
|
|
|
git --git-dir "$plugin_path/.git" remote get-url origin 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
get_plugin_remote_branch() {
|
|
|
|
local plugin_name="$1"
|
|
|
|
local plugin_path
|
|
|
|
plugin_path="$(get_plugin_path "$plugin_name")"
|
|
|
|
git --git-dir "$plugin_path/.git" rev-parse --abbrev-ref HEAD 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
get_plugin_remote_gitref() {
|
|
|
|
local plugin_name="$1"
|
|
|
|
local plugin_path
|
|
|
|
plugin_path="$(get_plugin_path "$plugin_name")"
|
|
|
|
git --git-dir "$plugin_path/.git" rev-parse --short HEAD 2>/dev/null
|
|
|
|
}
|