asdf/lib/commands/command-export-shell-version.bash

52 lines
1.1 KiB
Bash
Raw Normal View History

# -*- sh -*-
# Output from this command must be executable shell code
shell_command() {
local asdf_shell="$1"
shift
if [ "$#" -lt "2" ]; then
2020-09-21 15:27:52 -07:00
printf "Usage: asdf shell <name> {<version>|--unset}\\n" >&2
printf "false\\n"
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")
local version_env_var="ASDF_${upcase_name}_VERSION"
if [ "$version" = "--unset" ]; then
2020-01-25 13:35:36 -07:00
case "$asdf_shell" in
fish)
2020-09-21 15:27:52 -07:00
printf "set -e %s\\n" "$version_env_var"
;;
*)
2020-09-21 15:27:52 -07:00
printf "unset %s\\n" "$version_env_var"
;;
2020-01-25 13:35:36 -07:00
esac
exit 0
fi
if [ "$version" = "latest" ]; then
version=$(asdf latest "$plugin")
fi
if ! (check_if_version_exists "$plugin" "$version"); then
version_not_installed_text "$plugin" "$version" 1>&2
2020-09-21 15:27:52 -07:00
printf "false\\n"
exit 1
fi
case "$asdf_shell" in
fish)
2020-09-21 15:27:52 -07:00
printf "set -gx %s \"%s\"\\n" "$version_env_var" "$version"
;;
*)
2020-09-21 15:27:52 -07:00
printf "export %s=\"%s\"\\n" "$version_env_var" "$version"
;;
esac
}
shell_command "$@"