2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
2022-04-25 05:45:19 -07:00
|
|
|
# shellcheck source=lib/functions/versions.bash
|
|
|
|
. "$(dirname "$(dirname "$0")")/lib/functions/versions.bash"
|
2019-11-27 01:24:29 -07:00
|
|
|
|
|
|
|
# Output from this command must be executable shell code
|
|
|
|
shell_command() {
|
|
|
|
local asdf_shell="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ "$#" -lt "2" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Usage: asdf shell <name> {<version>|--unset}\n" >&2
|
|
|
|
printf "false\n"
|
2019-11-27 01:24:29 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local plugin=$1
|
|
|
|
local version=$2
|
|
|
|
|
|
|
|
local upcase_name
|
2020-09-21 15:27:52 -07:00
|
|
|
upcase_name=$(tr '[:lower:]-' '[:upper:]_' <<<"$plugin")
|
2019-11-27 01:24:29 -07:00
|
|
|
local version_env_var="ASDF_${upcase_name}_VERSION"
|
|
|
|
|
|
|
|
if [ "$version" = "--unset" ]; then
|
2020-01-25 13:35:36 -07:00
|
|
|
case "$asdf_shell" in
|
2020-06-29 16:16:35 -07:00
|
|
|
fish)
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "set -e %s\n" "$version_env_var"
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
2021-11-18 03:05:27 -07:00
|
|
|
elvish)
|
|
|
|
# Elvish doesn't have a `source` command, and eval is banned, so the
|
|
|
|
# var name and value are printed on separate lines for asdf.elv to parse
|
|
|
|
# and pass to unset-env.
|
|
|
|
printf "unset-env\n%s" "$version_env_var"
|
|
|
|
;;
|
2023-03-31 21:12:20 -07:00
|
|
|
pwsh)
|
|
|
|
printf '%s\n' "if (\$(Test-Path Env:$version_env_var) -eq 'True') { Remove-Item Env:$version_env_var }"
|
|
|
|
;;
|
2020-06-29 16:16:35 -07:00
|
|
|
*)
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "unset %s\n" "$version_env_var"
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
2020-01-25 13:35:36 -07:00
|
|
|
esac
|
2019-11-27 01:24:29 -07:00
|
|
|
exit 0
|
|
|
|
fi
|
2020-09-18 22:37:52 -07:00
|
|
|
if [ "$version" = "latest" ]; then
|
2022-04-25 05:45:19 -07:00
|
|
|
version=$(latest_command "$plugin")
|
2020-09-18 22:37:52 -07:00
|
|
|
fi
|
2019-11-27 01:24:29 -07:00
|
|
|
if ! (check_if_version_exists "$plugin" "$version"); then
|
2020-08-28 16:09:22 -07:00
|
|
|
version_not_installed_text "$plugin" "$version" 1>&2
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "false\n"
|
2019-11-27 01:24:29 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$asdf_shell" in
|
2020-06-29 16:16:35 -07:00
|
|
|
fish)
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "set -gx %s \"%s\"\n" "$version_env_var" "$version"
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
2021-11-18 03:05:27 -07:00
|
|
|
elvish)
|
|
|
|
# Elvish doesn't have a `source` command, and eval is banned, so the
|
|
|
|
# var name and value are printed on separate lines for asdf.elv to parse
|
|
|
|
# and pass to set-env.
|
|
|
|
printf "set-env\n%s\n%s" "$version_env_var" "$version"
|
|
|
|
;;
|
2023-03-31 21:12:20 -07:00
|
|
|
pwsh)
|
|
|
|
printf '%s\n' "\$Env:$version_env_var = '$version'"
|
|
|
|
;;
|
2020-06-29 16:16:35 -07:00
|
|
|
*)
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "export %s=\"%s\"\n" "$version_env_var" "$version"
|
2020-06-29 16:16:35 -07:00
|
|
|
;;
|
2019-11-27 01:24:29 -07:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
shell_command "$@"
|