Debian Codegraph @

init/zsh-functions/_module.in

raw
1 #compdef module
2
3 #
4 # Zsh command-line completion for module
5 # Copyright (C) 2017 Xavier Delaruelle <[email protected]>
6 #
7
8 _module_avail() {
9 local cur="${1:-}";
10 # skip avail call if word currently being completed is an option keyword
11 if [ -z "$cur" -o "${cur:0:1}" != '-' ]; then
12 module avail --color=never -s -t -S --no-indepth -o 'alias:indesym' $cur 2>&1
13 fi
14 }
15
16 _module_spider() {
17 local cur="${1:-}";
18 # skip spider call if word currently being completed is an option keyword
19 if [ -z "$cur" -o "${cur:0:1}" != '-' ]; then
20 module spider --color=never -s -t -S --no-indepth -o 'alias:indesym' $cur 2>&1
21 fi
22 }
23
24 _module_savelist() {
25 module savelist --color=never -s -t 2>&1 | sed '
26 /No named collection\.$/d;
27 /Named collection list$/d;
28 /:$/d;'
29 }
30
31 _module_stashlist() {
32 module stashlist --color=never -s -t 2>&1 | sed '
33 /No stash collection\.$/d;
34 /Stash collection list$/d;
35 /:$/d;'
36 }
37
38 _module_not_yet_loaded() {
39 _module_avail ${1:-} | sort | @SED_ERE@ "\%^(${LOADEDMODULES//:/|})$%d"
40 }
41
42
43 _module_avail_mods() {
44 local -a avail_mods;
45 local suffix=' ';
46 avail_mods=(${$(_module_avail $cur ${1:-})})
47
48 # do not append space to word completed if it is a directory (ends with /)
49 for val in $avail_mods; do
50 if [ "${val: -1:1}" = '/' ]; then
51 suffix=''
52 break
53 fi
54 done
55
56 compadd -S "$suffix" -a avail_mods && ret=0
57 }
58
59 _module_spider_mods() {
60 local -a spider_mods;
61 local suffix=' ';
62 spider_mods=(${$(_module_spider $cur ${1:-})})
63
64 # do not append space to word completed if it is a directory (ends with /)
65 for val in $spider_mods; do
66 if [ "${val: -1:1}" = '/' ]; then
67 suffix=''
68 break
69 fi
70 done
71
72 compadd -S "$suffix" -a spider_mods && ret=0
73 }
74
75 _module_saved_colls() {
76 local -a saved_colls;
77 saved_colls=(${$(_module_savelist)})
78
79 _describe -t saved-colls 'saved collections' saved_colls && ret=0
80 }
81
82 _module_stash_colls() {
83 local -a stash_colls;
84 stash_colls=(${$(_module_stashlist)})
85
86 _describe -t stash-colls 'stash collections' stash_colls && ret=0
87 }
88
89 _module_notloaded_mods() {
90 local -a not_yet_loaded_mods;
91 local suffix=' ';
92 not_yet_loaded_mods=(${$(_module_not_yet_loaded ${1:-})})
93
94 # do not append space to word completed if it is a directory (ends with /)
95 for val in $not_yet_loaded_mods; do
96 if [ "${val: -1:1}" = '/' ]; then
97 suffix=''
98 break
99 fi
100 done
101
102 compadd -S "$suffix" -a not_yet_loaded_mods && ret=0
103 }
104
105 _module_loaded_mods() {
106 local -a loaded_mods;
107 loaded_mods=(${=LOADEDMODULES//:/ })
108
109 _describe -t loaded-mods 'loaded modulefiles' loaded_mods && ret=0
110 }
111
112 _module_used_paths() {
113 local -a used_paths;
114 used_paths=(${=MODULEPATH//:/ })
115
116 _describe -t used-paths 'enabled modulepaths' used_paths && ret=0
117 }
118
119
120 _module() {
121 typeset -A opt_args
122
123 _arguments -C \
124 '(-T --trace)'{-T,--trace}'[Enable trace and debug messages]' \
125 '(-D --debug)'{-D,--debug}'[Enable debug messages]' \
126 '(-v --verbose)'{-v,--verbose}'[Enable verbose messages]' \
127 '(-s --silent)'{-s,--silent}'[Turn off error, warning and informational messages]' \
128 '(-h --help)'{-h,--help}'[Usage info]' \
129 '(-V --version)'{-V,--version}'[Module version]' \
130 '--dumpname[Module implementation name]' \
131 '(-w --width=)'{-w,--width=}'[Set output width]' \
132 '--paginate[Pipe mesg output into a pager if stream attached to terminal]' \
133 '--no-pager[Do not pipe message output into a pager]' \
134 '(--color --color=)'{--color,--color=}'[Colorize the output]' \
135 '--ignore-cache[Ignore module cache]' \
136 '--ignore-user-rc[Skip evaluation of user-specific module rc file]' \
137 '(-): :->cmd' \
138 '(-)*:: :->arg' && ret=0
139
140 case $state in
141 (cmd)
142 local -a cmds; cmds=(
143 'add:Load modulefile(s)'
144 'load:Load modulefile(s)'
145 'add-any:Load first available modulefile in list'
146 'load-any:Load first available modulefile in list'
147 'try-add:Attempt to load modulefile(s), no complain'
148 'try-load:Attempt to load modulefile(s), no complain'
149 'rm:Remove modulefile(s)'
150 'remove:Remove modulefile(s)'
151 'del:Remove modulefile(s)'
152 'unload:Remove modulefile(s)'
153 'purge:Unload all loaded modulefiles'
154 'reload:Unload then load all loaded modulefiles'
155 'update:Unload then load all loaded modulefiles'
156 'refresh:Refresh volatile components of loaded modulefiles'
157 'switch:Unload mod1 and load mod2'
158 'swap:Unload mod1 and load mod2'
159 'list:List loaded modules'
160 'avail:List all or matching available modules'
161 'spider:Scan all modulepaths and list all or matching available modules'
162 'is-avail:Is any of the modulefile(s) available'
163 'is-loaded:Test if any of the modulefile(s) are loaded'
164 'info-loaded:Get full name of matching loaded module(s)'
165 'aliases:List all module aliases'
166 'whatis:Print whatis information of modulefile(s)'
167 'apropos:Search all name and whatis containing str'
168 'keyword:Search all name and whatis containing str'
169 'search:Search all name and whatis containing str'
170 'save:Save current module list to collection'
171 'restore:Restore module list from collection or file'
172 'saverm:Remove saved collection'
173 'disable:Remove saved collection'
174 'saveshow:Display information about collection'
175 'describe:Display information about collection'
176 'savelist:List all saved collections'
177 'is-saved:Test if any of the collection(s) exists'
178 'initlist:List all modules loaded from init file'
179 'initadd:Add modulefile to shell init file'
180 'initrm:Remove modulefile from shell init file'
181 'initprepend:Add to beginning of list in init file'
182 'initswitch:Switch mod1 with mod2 from init file'
183 'initclear:Clear all modulefiles from init file'
184 'help:Print this or modulefile(s) help info'
185 'display:Display information about modulefile(s)'
186 'show:Display information about modulefile(s)'
187 'test:Test modulefile(s)'
188 'use:Add dir(s) to MODULEPATH variable'
189 'unuse:Remove dir(s) from MODULEPATH variable'
190 'is-used:Is any of the dir(s) enabled in MODULEPATH'
191 'path:Print modulefile path'
192 'paths:Print path of matching available modules'
193 'source:Execute scriptfile(s)'
194 'append-path:Append value to environment variable'
195 'prepend-path:Prepend value to environment variable'
196 'remove-path:Remove value from environment variable'
197 'clear:Reset Modules-specific runtime information'
198 'config:Display or set Modules configuration'
199 'sh-to-mod:Make modulefile from script env changes'
200 'edit:Open modulefile in editor'
201 'state:Display Modules state'
202 'lint:Check syntax of modulefile'
203 'mod-to-sh:Make shell code from modulefile env changes'
204 'reset:Restore initial environment'
205 'stash:Save current environment and reset'
206 'stashclear:Remove all stash collections'
207 'stashlist:List all stash collections'
208 'stashpop:Restore then remove stash collection'
209 'stashrm:Remove stash collection'
210 'stashshow:Display information about stash collection'
211 'cachebuild:Create cache file for modulepath(s)'
212 'cacheclear:Delete cache file in enabled modulepath(s)'
213 )
214 # show commands only with compatible options
215 if (( !$+opt_args[-h] && !$+opt_args[--help] \
216 && !$+opt_args[-V] && !$+opt_args[--version] \
217 && !$+opt_args[--dumpname] )); then
218 _describe -t cmds 'Module Sub-Commands' cmds && ret=0
219 fi
220 ;;
221 (arg)
222 local cmd="${words[1]}"
223 local cur="${words[CURRENT]}"
224 case $cmd in
225 (load|add|load-any|add-any|try-load|try-add)
226 _arguments \
227 '--auto[Enable automated module handling mode]' \
228 '--no-auto[Disable automated module handling mode]' \
229 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
230 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
231 '--tag=[Apply tag to loading module]' \
232 "*::modulefile:{_module_notloaded_mods $cur}" && ret=0
233 ;;
234 (avail)
235 _arguments \
236 '(-l --long)'{-l,--long}'[Display output in long format]' \
237 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
238 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
239 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
240 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
241 '(-d --default)'{-d,--default}'[Only show default versions available]' \
242 '(-L --latest)'{-L,--latest}'[Only show latest versions available]' \
243 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
244 '(-S --starts-with)'{-S,--starts-with}'[Search modules whose name begins with query string]' \
245 '(-C --contains)'{-C,--contains}'[Search modules whose name contains query string]' \
246 '--indepth[Perform recursive avail search]' \
247 '--no-indepth[Perform non-recursive avail search]' \
248 "*::modulefile:{_module_avail_mods $cur}" && ret=0
249 ;;
250 (spider)
251 _arguments \
252 '(-l --long)'{-l,--long}'[Display output in long format]' \
253 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
254 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
255 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
256 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
257 '(-d --default)'{-d,--default}'[Only show default versions available]' \
258 '(-L --latest)'{-L,--latest}'[Only show latest versions available]' \
259 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
260 '(-S --starts-with)'{-S,--starts-with}'[Search modules whose name begins with query string]' \
261 '(-C --contains)'{-C,--contains}'[Search modules whose name contains query string]' \
262 '--indepth[Perform recursive avail search]' \
263 '--no-indepth[Perform non-recursive avail search]' \
264 "*::modulefile:{_module_spider_mods $cur}" && ret=0
265 ;;
266 (aliases)
267 _arguments \
268 '(-a --all)'{-a,--all}'[Include hidden modules in search]' && ret=0
269 ;;
270 (list)
271 _arguments \
272 '(-l --long)'{-l,--long}'[Display output in long format]' \
273 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
274 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
275 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
276 '(-a --all)'{-a,--all}'[Include hidden modules in list]' && ret=0
277 ;;
278 (savelist)
279 local -a opts; opts=(
280 '-l:Display output in long format'
281 '--long:Display output in long format'
282 '-t:Display output in terse format'
283 '--terse:Display output in terse format'
284 '-j:Display output in JSON format'
285 '--json:Display output in JSON format'
286 '-o:Define elements to output in addition to module names'
287 '--output=:Define elements to output in addition to module names'
288 )
289 _describe -t opts 'Switches' opts && ret=0
290 ;;
291 (stashlist)
292 _arguments \
293 '(-l --long)'{-l,--long}'[Display output in long format]' \
294 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
295 '(-j --json)'{-j,--json}'[Display output in JSON format]' && ret=0
296 ;;
297 (stashpop|stashshow|stashrm)
298 _alternative 'avail-stashs:collections:{_module_stash_colls}' \
299 && ret=0
300 ;;
301 (clear)
302 _arguments \
303 '(-f --force)'{-f,--force}'[Skip confirmation dialog]' && ret=0
304 ;;
305 (restore|save|saveshow|describe|saverm|disable|is-saved)
306 _alternative 'avail-colls:collections:{_module_saved_colls}' \
307 && ret=0
308 ;;
309 (rm|del|remove|unload)
310 _arguments \
311 '--auto[Enable automated module handling mode]' \
312 '--no-auto[Disable automated module handling mode]' \
313 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
314 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
315 '*::modulefile:_module_loaded_mods' && ret=0
316 ;;
317 (switch|swap)
318 _arguments \
319 '--auto[Enable automated module handling mode]' \
320 '--no-auto[Disable automated module handling mode]' \
321 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
322 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
323 '--tag=[Apply tag to loading module]' \
324 '1:loaded modulefile:_module_loaded_mods' \
325 "2:modulefile:{_module_notloaded_mods $cur}" && ret=0
326 ;;
327 (unuse|is-used)
328 _alternative 'used-paths:modulepaths:{_module_used_paths}' \
329 && ret=0
330 ;;
331 (use)
332 _arguments \
333 '(-a --append)'{-a,--append}'[Append directory to MODULEPATH]' \
334 '(-p --prepend)'{-p,--prepend}'[Prepend directory to MODULEPATH]' \
335 '*:modulepath:_files -/' && ret=0
336 ;;
337 (cachebuild)
338 _arguments \
339 '*:modulepath:_files -/' && ret=0
340 ;;
341 (display|help|show|test|path|paths|is-loaded|info-loaded)
342 _arguments \
343 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
344 "*::modulefile:{_module_avail_mods $cur}" && ret=0
345 ;;
346 (is-avail)
347 _arguments \
348 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
349 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
350 "*::modulefile:{_module_avail_mods $cur}" && ret=0
351 ;;
352 (whatis)
353 _arguments \
354 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
355 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
356 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
357 "*::modulefile:{_module_avail_mods $cur}" && ret=0
358 ;;
359 (apropos|keyword|search)
360 _arguments \
361 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
362 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
363 && ret=0
364 ;;
365 (append-path|prepend-path)
366 _arguments \
367 '(-d --delim)'{-d,--delim}'[Path element separator]' \
368 '--duplicates[Duplicate existing element]' \
369 && ret=0
370 ;;
371 (remove-path)
372 _arguments \
373 '(-d --delim)'{-d,--delim}'[Path element separator]' \
374 '--index[Remove path element with index]' \
375 && ret=0
376 ;;
377 (config)
378 _arguments \
379 '--dump-state[Report each state value of current Modules execution]' \
380 '--reset[Unset environment variable relative to configuration key]' \
381 '1:configuration key:(abort_on_error advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output cache_buffer_bytes cache_expiry_secs collection_pin_version collection_pin_tag collection_target color colors conflict_unload contact editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_user_rc implicit_default implicit_requirement list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output require_via reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277)' \
382 && ret=0
383 ;;
384 (edit)
385 _arguments \
386 "*::modulefile:{_module_avail_mods $cur}" && ret=0
387 ;;
388 (lint)
389 _arguments \
390 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
391 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
392 "*::modulefile:{_module_avail_mods $cur}" && ret=0
393 ;;
394 (mod-to-sh)
395 _arguments \
396 '--auto[Enable automated module handling mode]' \
397 '--no-auto[Disable automated module handling mode]' \
398 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
399 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
400 "*::modulefile:{_module_notloaded_mods $cur}" && ret=0
401 ;;
402 esac
403 ;;
404 esac
405 }
406
407 _module "$@"
408
409 # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: