-
Notifications
You must be signed in to change notification settings - Fork 244
/
goenv-init
executable file
·154 lines (137 loc) · 2.44 KB
/
goenv-init
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# Summary: Configure the shell environment for goenv
# Usage: eval "$(goenv init - [--no-rehash] [<shell>])"
set -e
[ -n "$GOENV_DEBUG" ] && set -x
# Provide goenv completions
if [ "$1" = "--complete" ]; then
echo -
echo --no-rehash
echo bash
echo fish
echo ksh
echo zsh
exit
fi
print=""
no_rehash=""
for args in "$@"
do
if [ "$args" = "-" ]; then
print=1
shift
fi
if [ "$args" = "--no-rehash" ]; then
no_rehash=1
shift
fi
done
shell="$1"
if [ -z "$shell" ]; then
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)"
shell="${shell%% *}"
shell="${shell##-}"
shell="${shell:-$SHELL}"
shell="${shell##*/}"
fi
root="${0%/*}/.."
if [ -z "$print" ]; then
case "$shell" in
bash )
if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then
profile='~/.bashrc'
else
profile='~/.bash_profile'
fi
;;
zsh )
profile='~/.zshrc'
;;
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
esac
{ echo "# Load goenv automatically by appending"
echo "# the following to ${profile}:"
echo
case "$shell" in
fish )
echo 'status --is-interactive; and source (goenv init -|psub)'
;;
* )
echo 'eval "$(goenv init -)"'
;;
esac
echo
} >&2
exit 1
fi
mkdir -p "${GOENV_ROOT}/"{shims,versions}
case "$shell" in
fish )
echo "set -gx PATH '${GOENV_ROOT}/shims' \$PATH"
echo "set -gx GOENV_SHELL $shell"
;;
* )
echo 'export PATH="'${GOENV_ROOT}'/shims:${PATH}"'
echo "export GOENV_SHELL=$shell"
;;
esac
completion="${root}/completions/goenv.${shell}"
if [ -r "$completion" ]; then
echo "source '$completion'"
fi
if [ -z "$no_rehash" ]; then
echo 'command goenv rehash 2>/dev/null'
fi
commands=(`goenv-commands --sh`)
case "$shell" in
fish )
cat <<EOS
function goenv
set command \$argv[1]
set -e argv[1]
switch "\$command"
case ${commands[*]}
source (goenv "sh-\$command" \$argv|psub)
case '*'
command goenv "\$command" \$argv
end
end
EOS
;;
ksh )
cat <<EOS
function goenv {
typeset command
EOS
;;
* )
cat <<EOS
goenv() {
local command
EOS
;;
esac
if [ "$shell" != "fish" ]; then
IFS="|"
cat <<EOS
command="\$1"
if [ "\$#" -gt 0 ]; then
shift
fi
case "\$command" in
${commands[*]})
eval "\$(goenv "sh-\$command" "\$@")";;
*)
command goenv "\$command" "\$@";;
esac
}
EOS
fi