forked from tgenv/tgenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tgenv
executable file
·63 lines (57 loc) · 1.2 KB
/
tgenv
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
62
63
#!/usr/bin/env bash
set -e
if [ -n "${TGENV_DEBUG}" ]; then
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
set -x
fi
# http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
readlink_f() {
local target_file="${1}"
local file_name
while [ "${target_file}" != "" ]; do
cd "$(dirname ${target_file})"
file_name="$(basename "${target_file}")"
target_file="$(readlink "${file_name}")"
done
echo "$(pwd -P)/${file_name}"
}
if [ -z "${TGENV_ROOT}" ]; then
TGENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"
else
TGENV_ROOT="${TGENV_ROOT%/}"
fi
export TGENV_ROOT
PATH="${TGENV_ROOT}/libexec:${PATH}"
export PATH
export TGENV_DIR="${PWD}"
abort() {
{ if [ "${#}" -eq 0 ]; then cat -
else echo "tgenv: ${*}"
fi
} >&2
exit 1
}
command="${1}"
case "${command}" in
"" )
{ tgenv---version
tgenv-help
} | abort
;;
-v | --version )
exec tgenv---version
;;
-h | --help )
exec tgenv-help
;;
* )
command_path="$(command -v "tgenv-${command}" || true)"
if [ -z "${command_path}" ];then
{ echo "no such command '${command}'"
tgenv-help
} | abort
fi
shift 1
exec "${command_path}" "${@}"
;;
esac