-
Notifications
You must be signed in to change notification settings - Fork 7
/
asdf-get-asdf-bin
executable file
·61 lines (55 loc) · 1.85 KB
/
asdf-get-asdf-bin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -euo pipefail
#- asdf-get-asdf-bin 1.0
## Usage: asdf-get-asdf-bin
## Print the ASDF_BIN environment variables as it would be set after enabling 'asdf'.
##
## -h, --help Display this help and exit
## -v, --version Output version information and exit
if { getopt --test >/dev/null 2>&1 && false; } || [[ "$?" = "4" ]] || false; then
ARGS=$(getopt -o hv -l help,version -n $(basename ${BASH_SOURCE[0]}) -- "$@") || sh_script_usage
eval set -- "${ARGS}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
sh_script_usage
;;
-v|--version)
sh_script_version
;;
--)
shift
break
;;
-*)
sh_script_usage
;;
*)
break
;;
esac
done
[[ $# -eq 0 ]] || sh_script_usage
# command is defined and is a function (no path)
[[ "$(command -v asdf 2>&1)" = "asdf" ]] || {
# using a less exact call because 'brew --prefix asdf' is very very slow
# BREW_ASDF_DIR=$(brew --prefix asdf 2>/dev/null || true)
BREW_ASDF_DIR=$(brew --prefix)/opt/asdf
ASDF_SH=
[[ ! -f /opt/.asdf/asdf.sh ]] || ASDF_SH=/opt/.asdf/asdf.sh
[[ ! -f ${HOME}/.asdf/asdf.sh ]] || ASDF_SH=${HOME}/.asdf/asdf.sh
[[ ! -f ${XDG_CONFIG_HOME:-}/asdf/asdf.sh ]] || ASDF_SH=${XDG_CONFIG_HOME}/asdf/asdf.sh
[[ ! -f ${BREW_ASDF_DIR}/asdf.sh ]] || ASDF_SH=${BREW_ASDF_DIR}/asdf.sh
[[ ! -f ${BREW_ASDF_DIR}/libexec/asdf.sh ]] || ASDF_SH=${BREW_ASDF_DIR}/libexec/asdf.sh
[[ -n ${ASDF_SH} ]] || {
>&2 echo "$(date +"%H:%M:%S")" "[WARN] Couldn't find asdf in any of the known locations."
exit 0
}
NOUNSET_STATE="$(set +o | grep nounset)"
set +u
source ${ASDF_SH}
eval "${NOUNSET_STATE}"
unset NOUNSET_STATE
}
[[ -z "${ASDF_DIR:-}" ]] || echo ${ASDF_DIR}/bin