This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
_zinit
366 lines (315 loc) · 14 KB
/
_zinit
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#compdef zinit
setopt localoptions warncreateglobal typesetsilent
local curcontext="$curcontext" state state_descr line ret=1
local -a expl
typeset -a commands
commands=(
zstatus:'overall Zinit status'
times:'statistics on plugin loading times'
self-update:'updates Zinit'
help:'usage information'
man:'manual'
env-whitelist:'specify names (also patterns) of parameters to be left unchanged during an unload'
load:'load plugin'
delete:'delete plugin'
unload:'unload plugin'
snippet:"source (or add to PATH with --command) local or remote file (-f: force - don't use cache)"
update:'Git update plugin (or all plugins and snippets if --all passed)'
status:'Git status for plugin (or all plugins if --all passed)'
report:'show plugin'"'"'s report (or all plugins'"'"' if --all passed)'
loaded:'show what plugins are loaded'
list:'show what plugins are loaded'
ls:'list snippets in formatted and colorized manner'
cd:"go into plugin's directory"
create:'create plugin (also together with Github repository)'
edit:"edit plugin's file with \$EDITOR"
glance:"look at plugin's source (pygmentize, {,source-}highlight)"
stress:'test plugin for compatibility with set of options'
changes:"view plugin's git log"
recently:"show plugins that changed recently, argument is e.g. 1 month 2 days"
clist:'list completions in use'
cclear:'clear stray and improper completions'
completions:'list completions in use'
cdisable:'disable completion'
cenable:'enable completion'
creinstall:'install completions for plugin'
cuninstall:'uninstall completions for plugin'
csearch:'search for available completions from any plugin'
compinit:'refresh installed completions'
dtrace:"start tracking what's going on in session"
dstart:"start tracking what's going on in session"
dstop:"stop tracking what's going on in session"
dunload:'revert changes recorded between dstart and dstop'
dreport:"report what was going on in session"
dclear:'clear report of what was going on in session'
compile:'compile plugin (or all plugins if --all passed)'
uncompile:'remove compiled version of plugin (or of all plugins if --all passed)'
compiled:'show which plugins are compiled'
cdlist:'show compdef replay list'
cdreplay:'replay compdefs (to be done after compinit)'
cdclear:'clear compdef replay list'
srv:'control a service, command can be: stop,start,restart,next,quit; `next'' moves the service to another Zshell'
recall:'fetch saved ice modifiers and construct `zinit ice ...'' command'
env-whitelist:'allows to specify names (also patterns) of variables left unchanged during an unload. -v - verbose'
bindkeys:'lists bindkeys set up by each plugin'
module:'manage binary Zsh module shipped with Zinit, see `zinit module help'''
run:"execute code inside plugin's folder"
{add-fpath,fpath}:'add plugin folder to $fpath'
)
_arguments -C \
'1: :->command'\
'*: :->argument' && ret=0
case $state in
command)
_describe -t commands "Zinit command" commands && ret=0
;;
argument)
case $words[2] in
help)
_message "Hit enter to get usage information" && ret=0
;;
man)
_message "Hit enter to view manual" && ret=0
;;
zstatus)
_message "Hit enter to get overall status information" && ret=0
;;
times)
_message "Hit enter to get plugin load time statistics" && ret=0
;;
load|light)
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) )
plugins=( "${plugins[@]//---//}" )
plugins=( "${plugins[@]:#_local/zinit}" )
plugins=( "${plugins[@]:#custom}" )
_alternative \
'plugins:-- Plugin --:compadd -a - plugins' \
'directories:-- Directory --:_directories' && \
ret=0
;;
run|fpath|add-fpath)
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) )
plugins=( "${plugins[@]//---//}" )
plugins=( "${plugins[@]:#_local/zinit}" )
plugins=( "${plugins[@]:#custom}" )
local -a opts
if [[ $words[2] = run ]]; then
opts=( -l )
else
opts=( -f --front )
fi
_alternative \
'plugins:-- Plugin --:compadd -a - plugins' \
'directories:-- Directory --:_directories' \
'opts:-- Option --:compadd -a - opts' && \
ret=0
;;
compile|stress|edit|glance|recall|update|status|cd|changes|delete)
# Plugins
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N:t) )
plugins=( "${plugins[@]//---//}" )
plugins=( "${plugins[@]:#_local/zinit}" )
plugins=( "${plugins[@]:#custom}" )
# Snippets
local -a snippets snippets_alreadyld
local sni
snippets=( "${ZINIT[SNIPPETS_DIR]}"/**/._zinit(D/:h) )
snippets=( ${snippets[@]#${ZINIT[SNIPPETS_DIR]}/} )
snippets=( ${snippets[@]/(#b)(http|https|ftp|ftps|scp)--/${match[1]}://} )
snippets=( ${snippets[@]/--//} )
for sni ( ${snippets[@]} ) {
if [[ -n ${ZINIT_SNIPPETS[$sni]} ]]; then
snippets_alreadyld+=( $sni )
snippets=( ${snippets[@]:#$sni} )
fi
}
_alternative 'dsnippets:-- Downloaded Snippet --:compadd -a - snippets' \
'lsnippets:-- Already Loaded Snippet --:compadd -a - snippets_alreadyld' \
'plugins:-- Plugin --:compadd -a - plugins' && \
ret=0
;;
unload|report)
typeset -a plugins absolute normal
plugins=( "${ZINIT_REGISTERED_PLUGINS[@]:#_local/zinit}" )
normal=( "${plugins[@]:#%*}" )
absolute=( "${(M)plugins[@]:#%*}" )
absolute=( "${absolute[@]/\%\/\//%/}" )
local hm="${HOME%/}"
absolute=( "${absolute[@]/$hm/HOME}" )
plugins=( $normal $absolute )
_wanted plugins expl "-- Plugin --" \
compadd "$@" -a - plugins && \
ret=0
;;
all-reports)
_message "Hit enter to get all reports (for all loaded plugins)" && ret=0
;;
loaded|list)
_message "Hit enter or give part of plugin name" && ret=0
;;
clist|completions)
_message "Hit enter to get list of completions" && ret=0
;;
cclear)
_message "Hit enter to clear stray and improper completions" && ret=0
;;
cdisable)
# Find enabled completions
typeset -a completions
completions=( "${ZINIT[COMPLETIONS_DIR]}"/_*(N:t) )
completions=( "${completions[@]#_}" )
_wanted plugins expl "-- Completion --" \
compadd "$@" -a - completions && \
ret=0
;;
cenable)
# Find disabled
typeset -a completions
completions=( "${ZINIT[COMPLETIONS_DIR]}"/[^_]*(N:t) )
_wanted plugins expl "-- Completion --" \
compadd "$@" -a - completions && \
ret=0
;;
creinstall)
# Complete only plugins that have any completions
# We must iterate each plugin to check
# for completions that can be installed
typeset -a plugins completions
local p c user plugin
for p in "${ZINIT[PLUGINS_DIR]}"/*; do
completions=( "$p"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|_zsh_highlight*|/zsdoc/*)(DN) )
for c in "${completions[@]}"; do
p="${p:t}"
user="${p%%---*}"
plugin="${p#*---}"
[[ "$user" = "$plugin" && "${user}---${plugin}" != "$p" ]] && user=""
plugins+=( "${user:+$user/}$plugin" )
break
done
done
_wanted plugins expl "-- Plugin --" \
compadd "$@" -a - plugins && \
ret=0
;;
cuninstall)
# We must iterate each plugin and check if
# it has completions that are installed
typeset -a plugins completions
local p c user plugin cfile bkpfile
for p in "${ZINIT[PLUGINS_DIR]}"/*; do
completions=( "$p"/**/_[^_.][^.]#(N) )
for c in "${completions[@]}"; do
cfile="${c:t}"
bkpfile="${cfile#_}"
# Completion installed, either enabled or disabled?
if [[ -e "${ZINIT[COMPLETIONS_DIR]}"/"$cfile" || -e "${ZINIT[COMPLETIONS_DIR]}"/"$bkpfile" ]]; then
p="${p:t}"
user="${p%%---*}"
plugin="${p#*---}"
[[ "$user" = "$plugin" && "${user}---${plugin}" != "$p" ]] && user=""
plugins+=( "${user:+$user/}$plugin" )
break
fi
done
done
_wanted plugins expl "-- Plugin --" \
compadd "$@" -a - plugins && \
ret=0
;;
compinit)
_message "Hit enter to refresh completion system" && ret=0
;;
snippet)
local -a snippets snippets_alreadyld
local sni
snippets=( "${ZINIT[SNIPPETS_DIR]}"/**/._zinit(D/:h) )
snippets=( ${snippets[@]#${ZINIT[SNIPPETS_DIR]}/} )
snippets=( ${snippets[@]/(#b)(http|https|ftp|ftps|scp)--/${match[1]}://} )
snippets=( ${snippets[@]/--//} )
for sni ( ${snippets[@]} ) {
if [[ -n ${ZINIT_SNIPPETS[$sni]} ]]; then
snippets_alreadyld+=( $sni )
snippets=( ${snippets[@]:#$sni} )
fi
}
_alternative 'dsnippets:-- Downloaded Snippet --:compadd -a - snippets' \
'lsnippets:-- Already Loaded Snippet --:compadd -a - snippets_alreadyld' \
'files:-- File --:_files' && \
ret=0
;;
dstart|dtrace)
_message "Hit enter to start tracking this session" && ret=0
;;
dstop)
_message "Hit enter to stop tracking this session" && ret=0
;;
dunload)
_message "Hit enter to revert changes recorded between dstart and dstop" && ret=0
;;
dreport)
_message "Hit enter to show report of what was going on in session" && ret=0
;;
dclear)
_message "Hit enter to clear report of what was going on in session" && ret=0
;;
compile-all)
_message 'Hit enter to compile all downloaded plugins' && ret=0
;;
uncompile)
typeset -a plugins
plugins=( "${ZINIT[PLUGINS_DIR]}"/*(N) )
typeset -a show_plugins p matches
for p in "${plugins[@]}"; do
matches=( $p/*.zwc(N) )
if [ "$#matches" -ne "0" ]; then
p="${p:t}"
[ "$p" = "_local---zinit" ] && continue
[ "$p" = "custom" ] && continue
p="${p//---//}"
show_plugins+=( "$p" )
fi
done
_wanted show_plugins expl "-- Plugin --" \
compadd "$@" -a - show_plugins && \
ret=0
;;
uncompile-all)
_message 'Hit enter remove compiled versions of all downloaded plugins' && ret=0
;;
compiled)
_message 'Hit enter to get list of compiled plugins' && ret=0
;;
cdlist)
_message 'Hit enter to show compdef replay list' && ret=0
;;
cdreplay)
_message 'Hit enter to replay recorded compdefs' && ret=0
;;
cdclear)
_message 'Hit enter to clear compdef replay list' && ret=0
;;
recently)
typeset -a timespecs
timespecs=(
"3 days":"code modified during last 3 days"
"1 week":"code modified during last 7 days (default)"
"1 month":"code modified during last month"
)
_describe -t timespecs "Time spec" timespecs && ret=0
;;
create)
_message 'Plugin spec or just enter, to create new plugin' && ret=0
;;
env-whitelist)
_wanted plugins expl "-- Parameter To White List During Any Plugin Unload --" \
_parameters && ret=0
;;
*)
ret=1
;;
esac
esac
return $ret