-
Notifications
You must be signed in to change notification settings - Fork 0
/
→za-bgn-atclone-handler
216 lines (177 loc) · 7.82 KB
/
→za-bgn-atclone-handler
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Copyright (c) 2019 Sebastian Gniazdowski
# License MIT
emulate -RL zsh
setopt extendedglob warncreateglobal typesetsilent noshortloops
[[ "$1" = plugin ]] && \
local type="$1" user="$2" plugin="$3" id_as="$4" dir="$5" hook="$6" || \
local type="$1" url="$2" id_as="$3" dir="$4" hook="$5"
local nl=$'\n'
if [[ -n "${ZINIT_ICE[gem]}" ]] {
local -a gem_defs srcdst tmpsdst gems
gem_defs=( "${(s.;.)ZINIT_ICE[gem]}" )
local gem
for gem ( $gem_defs ) {
srcdst=( ${(@s.->.)gem} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
gems+=( ${srcdst[2]} )
}
(( ${#gems} )) && {
if [[ "$hook" = *atclone ]]; then
command gem install -q --no-user-install -i "$dir" "${gems[@]}"
elif [[ "$hook" = *atpull ]]; then
if (( !ICE_OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the gems...%f"
command gem update -q --no-user-install -i "$dir" "${gems[@]}"
} else {
command gem update -q --no-user-install -i "$dir" "${gems[@]}" &> /dev/null
}
fi
}
}
if [[ -n "${ZINIT_ICE[node]}" ]] {
local -a node_defs srcdst tmpsdst mods
node_defs=( "${(s.;.)ZINIT_ICE[node]}" )
local node
integer perform_update=0
for node ( $node_defs ) {
srcdst=( ${(@s.->.)node} )
tmpsdst=( ${(@s.<-.)srcdst[1]} )
if (( ${#tmpsdst} > 1 )); then
srcdst=( "${tmpsdst[1]}" "${tmpsdst[2]}" "${srcdst[2]:-${tmpdist[2]#\!}}" )
else
srcdst=( "${tmpsdst[1]#\!}" "${tmpsdst[1]}" "${srcdst[2]:-${srcdst[1]#\!}}" )
fi
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[2]=${srcdst[2]#\!}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]' 'srcdst[3]'
if [[ "$hook" = *atclone ]]; then
mods+=( ${srcdst[2]} )
elif [[ "$hook" = *atpull && -n ${srcdst[2]} ]]; then
perform_update=1
break
fi
}
(( ${#mods} )) && \
( builtin cd -q "$dir" && command npm --silent install "${mods[@]}" )
(( perform_update )) && \
(
builtin cd -q "$dir" && {
if (( !ICE_OPTS[opt_-q,--quiet] )) {
print -P -- "%F{38}bin-gem-node annex: %F{154}Updating the node modules...%f"
command npm --silent update
} else {
command npm --silent update &> /dev/null
}
}
)
}
#
# sbin'' ice – creation of shims (the name borrowed from rbenv)
#
if (( ${+ZINIT_ICE[sbin]} )) {
local -a sbins srcdst
sbins=( ${(s.;.)ZINIT_ICE[sbin]} )
local sbin
(
# CD for the globbing through eval
builtin cd -q "$dir" || return
for sbin ( $sbins "" ) {
integer set_gem_home=0 set_node_path=0 set_cwd=0 \
use_all_null=0 use_err_null=0 use_out_null=0
if [[ -z $sbin && ${#sbins} -eq 0 ]]; then
if [[ -f $dir/${id_as:t} ]]; then
sbin="$dir/${id_as:t}"
elif [[ -n $plugin && -f $dir/$plugin ]]; then
sbin="$dir/$plugin"
elif [[ -n $url && -f $dir/${url:t} ]]; then
sbin="$dir/${url:t}"
else
local -a files
files=( $dir/*(*Nnon:t) )
if (( ${#files} )); then
sbin="${files[1]}"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}The automatic-empty sbin ice didn't find any executable files%f"
break
fi
fi
elif [[ -z $sbin ]]; then
continue
fi
srcdst=( ${(@s.->.)sbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
[[ ${srcdst[1]} = [gncNEO]#g[gncNEO]#:* ]] && set_gem_home=1
[[ ${srcdst[1]} = [gncNEO]#n[gncNEO]#:* ]] && set_node_path=1
[[ ${srcdst[1]} = [gncNEO]#c[gncNEO]#:* ]] && set_cwd=1
[[ ${srcdst[1]} = [gncNEO]#N[gncNEO]#:* ]] && use_all_null=1
[[ ${srcdst[1]} = [gncNEO]#E[gncNEO]#:* ]] && use_err_null=1
[[ ${srcdst[1]} = [gncNEO]#O[gncNEO]#:* ]] && use_out_null=1
srcdst[1]=${srcdst[1]#[a-zA-Z]#:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]' 'srcdst[2]'
local -a fnames
local fname
eval "fnames=( ${srcdst[1]}(Nnon) )"
if (( !${#fnames} )) {
print -P -- "%F{38}bin-gem-node annex: %F{160}Warning: %F{154}The sbin'' ice (\`%F{219}$sbin%F{154}') didn't match any files%f"
continue
}
for fname ( $fnames ) {
srcdst[1]="$fname"
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
fnam="${srcdst[2]:-${srcdst[1]:t}}"
local file="$ZPFX/bin/$fnam"
.za-bgn-bin-or-src-function-body 0 \
"$fnam" \
"$target_binary" "$dir" "$set_gem_home" \
"$set_node_path" "$set_cwd" "$use_all_null" \
"$use_err_null" "$use_out_null"
builtin print -r -- "#!/usr/bin/env zsh$nl$nl$REPLY$nl$nl$fnam \"\$@\"" \
>! "$file"
command chmod +x "$file" "$target_binary"
if [[ -x $file ]]; then
(( !ICE_OPTS[opt_-q,--quiet] )) && \
if [[ -x $target_binary ]]; then
[[ $hook == atclone || $ZINIT[annex-multi-flag:pull-active] == 2 ]] && \
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim and set +x on the %F{219}${target_binary:t}%F{154} binary%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{154}${${${hook:#*atclone}:+Re-c}:-C}reated the %F{219}$fnam%F{154} shim %F{160}however the %F{219}${target_binary:t}%F{160} binary does not exist or failed to set +x on it%f"
fi
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong creating the %F{219}$fnam%F{160} shim%f"
fi
}
}
)
}
if [[ -n "${ZINIT_ICE[fbin]}" ]] {
local -a fbins srcdst
fbins=( "${(s.;.)ZINIT_ICE[fbin]}" )
local fbin
for fbin ( $fbins ) {
srcdst=( ${(@s.->.)fbin} )
srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" )
srcdst[1]=${srcdst[1]#[a-zA-Z]##:}
# Substitute the standard keywords and param''-s
@zinit-substitute 'srcdst[1]'
local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \
command chmod +x "$target_binary"
if [[ -x $target_binary ]]; then
(( !ICE_OPTS[opt_-q,--quiet] )) && \
print -P -- "%F{38}bin-gem-node annex: %F{154}Set +x on the %F{219}${target_binary:t}%F{154} binary%f"
else
print -P -- "%F{38}bin-gem-node annex: %F{160}Something went wrong setting +x on the %F{219}${target_binary:t}%F{160} binary%f"
fi
}
}
# vim:ft=zsh:sw=4:sts=4:et