-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathluaenv
executable file
·110 lines (93 loc) · 2.26 KB
/
luaenv
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
set -e
export -n CDPATH
if [ "$1" = "--debug" ]; then
export LUAENV_DEBUG=1
shift
fi
if [ -n "$LUAENV_DEBUG" ]; then
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
set -x
fi
if enable -f "${0%/*}"/../libexec/luaenv-realpath.dylib realpath 2>/dev/null; then
abs_dirname() {
local path="$(realpath "$1")"
echo "${path%/*}"
}
else
if [ -n "$LUAENV_NATIVE_EXT" ]; then
echo "luaenv: failed to load \`realpath' builtin" >&2
exit 1
fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "luaenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK "$1"
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
fi
if [ -z "${LUAENV_ROOT}" ]; then
LUAENV_ROOT="${HOME}/.luaenv"
else
LUAENV_ROOT="${LUAENV_ROOT%/}"
fi
export LUAENV_ROOT
if [ -z "${LUAENV_DIR}" ]; then
LUAENV_DIR="$(pwd)"
else
cd "$LUAENV_DIR" 2>/dev/null || {
echo "luaenv: cannot change working directory to \`$LUAENV_DIR'"
exit 1
} >&2
LUAENV_DIR="$(pwd)"
cd "$OLDPWD"
fi
export LUAENV_DIR
shopt -s nullglob
bin_path="$(abs_dirname "$0")"
for plugin_bin in "${LUAENV_ROOT}/plugins/"*/bin; do
PATH="${plugin_bin}:${PATH}"
done
export PATH="${bin_path}:${PATH}"
LUAENV_HOOK_PATH="${LUAENV_HOOK_PATH}:${LUAENV_ROOT}/luaenv.d"
if [ "${bin_path%/*}" != "$LUAENV_ROOT" ]; then
# Add luaenv's own `luaenv.d` unless luaenv was cloned to LUAENV_ROOT
LUAENV_HOOK_PATH="${LUAENV_HOOK_PATH}:${bin_path%/*}/luaenv.d"
fi
LUAENV_HOOK_PATH="${LUAENV_HOOK_PATH}:/usr/local/etc/luaenv.d:/etc/luaenv.d:/usr/lib/luaenv/hooks"
for plugin_hook in "${LUAENV_ROOT}/plugins/"*/etc/luaenv.d; do
LUAENV_HOOK_PATH="${LUAENV_HOOK_PATH}:${plugin_hook}"
done
export LUAENV_HOOK_PATH
shopt -u nullglob
command="$1"
case "$command" in
"" | "-h" | "--help" )
echo -e "$(luaenv---version)\n$(luaenv-help)" >&2
;;
"-v" )
exec luaenv---version
;;
* )
command_path="$(command -v "luaenv-$command" || true)"
if [ -z "$command_path" ]; then
echo "luaenv: no such command \`$command'" >&2
exit 1
fi
shift 1
exec "$command_path" "$@"
;;
esac