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 '(-p --paginate)'{-p,--paginate}'[Pipe mesg output into a pager if stream attached to terminal]' \
133 '(-P --no-pager)'{-P,--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 '--no-modulepath-ignore[Do not apply modulepath-ignore pattern definitions]' \
138 '--timer[Report execution times]' \
139 '--redirect[Send output to stdout]' \
140 '--no-redirect[Send output to stderr]' \
141 '(-): :->cmd' \
142 '(-)*:: :->arg' && ret=0
143
144 case $state in
145 (cmd)
146 local -a cmds; cmds=(
147 'add:Load modulefile(s)'
148 'load:Load modulefile(s)'
149 'add-any:Load first available modulefile in list'
150 'load-any:Load first available modulefile in list'
151 'try-add:Attempt to load modulefile(s), no complain'
152 'try-load:Attempt to load modulefile(s), no complain'
153 'rm:Remove modulefile(s)'
154 'remove:Remove modulefile(s)'
155 'delete:Remove modulefile(s)'
156 'unload:Remove modulefile(s)'
157 'purge:Unload all loaded modulefiles'
158 'reload:Unload then load all loaded modulefiles'
159 'update:Unload then load all loaded modulefiles'
160 'refresh:Refresh volatile components of loaded modulefiles'
161 'switch:Unload mod1 and load mod2'
162 'swap:Unload mod1 and load mod2'
163 'list:List loaded modules'
164 'avail:List all or matching available modules'
165 'spider:Scan all modulepaths and list all or matching available modules'
166 'is-avail:Is any of the modulefile(s) available'
167 'is-loaded:Test if any of the modulefile(s) are loaded'
168 'info-loaded:Get full name of matching loaded module(s)'
169 'aliases:List all module aliases'
170 'whatis:Print whatis information of modulefile(s)'
171 'apropos:Search all name and whatis containing str'
172 'keyword:Search all name and whatis containing str'
173 'search:Search all name and whatis containing str'
174 'save:Save current module list to collection'
175 'restore:Restore module list from collection or file'
176 'saverm:Remove saved collection'
177 'disable:Remove saved collection'
178 'saveshow:Display information about collection'
179 'describe:Display information about collection'
180 'savelist:List all saved collections'
181 'is-saved:Test if any of the collection(s) exists'
182 'help:Print this or modulefile(s) help info'
183 'display:Display information about modulefile(s)'
184 'show:Display information about modulefile(s)'
185 'test:Test modulefile(s)'
186 'use:Add dir(s) to MODULEPATH variable'
187 'unuse:Remove dir(s) from MODULEPATH variable'
188 'is-used:Is any of the dir(s) enabled in MODULEPATH'
189 'path:Print modulefile path'
190 'paths:Print path of matching available modules'
191 'source:Execute scriptfile(s)'
192 'append-path:Append value to environment variable'
193 'prepend-path:Prepend value to environment variable'
194 'remove-path:Remove value from environment variable'
195 'clear:Reset Modules-specific runtime information'
196 'config:Display or set Modules configuration'
197 'sh-to-mod:Make modulefile from script env changes'
198 'edit:Open modulefile in editor'
199 'state:Display Modules state'
200 'lint:Check syntax of modulefile'
201 'mod-to-sh:Make shell code from modulefile env changes'
202 'reset:Restore initial environment'
203 'stash:Save current environment and reset'
204 'stashclear:Remove all stash collections'
205 'stashlist:List all stash collections'
206 'stashpop:Restore then remove stash collection'
207 'stashrm:Remove stash collection'
208 'stashshow:Display information about stash collection'
209 'cachebuild:Create cache file for modulepath(s)'
210 'cacheclear:Delete cache file in enabled modulepath(s)'
211 )
212 # show commands only with compatible options
213 if (( !$+opt_args[-h] && !$+opt_args[--help] \
214 && !$+opt_args[-V] && !$+opt_args[--version] \
215 && !$+opt_args[--dumpname] )); then
216 _describe -t cmds 'Module Sub-Commands' cmds && ret=0
217 fi
218 ;;
219 (arg)
220 local cmd="${words[1]}"
221 local cur="${words[CURRENT]}"
222 case $cmd in
223 (load|add|load-any|add-any|try-load|try-add)
224 _arguments \
225 '--auto[Enable automated module handling mode]' \
226 '--no-auto[Disable automated module handling mode]' \
227 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
228 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
229 '--tag=[Apply tag to loading module]' \
230 "*::modulefile:{_module_notloaded_mods $cur}" && ret=0
231 ;;
232 (avail)
233 _arguments \
234 '(-l --long)'{-l,--long}'[Display output in long format]' \
235 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
236 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
237 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
238 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
239 '(-d --default)'{-d,--default}'[Only show default versions available]' \
240 '(-L --latest)'{-L,--latest}'[Only show latest versions available]' \
241 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
242 '(-S --starts-with)'{-S,--starts-with}'[Search modules whose name begins with query string]' \
243 '(-C --contains)'{-C,--contains}'[Search modules whose name contains query string]' \
244 '--indepth[Perform recursive avail search]' \
245 '--no-indepth[Perform non-recursive avail search]' \
246 "*::modulefile:{_module_avail_mods $cur}" && ret=0
247 ;;
248 (spider)
249 _arguments \
250 '(-l --long)'{-l,--long}'[Display output in long format]' \
251 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
252 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
253 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
254 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
255 '(-d --default)'{-d,--default}'[Only show default versions available]' \
256 '(-L --latest)'{-L,--latest}'[Only show latest versions available]' \
257 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
258 '(-S --starts-with)'{-S,--starts-with}'[Search modules whose name begins with query string]' \
259 '(-C --contains)'{-C,--contains}'[Search modules whose name contains query string]' \
260 '--indepth[Perform recursive avail search]' \
261 '--no-indepth[Perform non-recursive avail search]' \
262 "*::modulefile:{_module_spider_mods $cur}" && ret=0
263 ;;
264 (aliases)
265 _arguments \
266 '(-a --all)'{-a,--all}'[Include hidden modules in search]' && ret=0
267 ;;
268 (list)
269 _arguments \
270 '(-l --long)'{-l,--long}'[Display output in long format]' \
271 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
272 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
273 '(-o --output=)'{-o,--output=}'[Define elements to output in addition to module names]' \
274 '(-a --all)'{-a,--all}'[Include hidden modules in list]' \
275 '(-S --starts-with)'{-S,--starts-with}'[Search modules whose name begins with query string]' \
276 '(-C --contains)'{-C,--contains}'[Search modules whose name contains query string]' && 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 '-a:Include hidden modules in search'
287 '--all:Include hidden modules in search'
288 '-S:Search modules whose name begins with query string'
289 '--starts-with:Search modules whose name begins with query string'
290 '-C:Search modules whose name contains query string'
291 '--contains:Search modules whose name contains query string'
292 )
293 _describe -t opts 'Switches' opts && ret=0
294 ;;
295 (stashlist)
296 _arguments \
297 '(-l --long)'{-l,--long}'[Display output in long format]' \
298 '(-t --terse)'{-t,--terse}'[Display output in terse format]' \
299 '(-j --json)'{-j,--json}'[Display output in JSON format]' && ret=0
300 ;;
301 (stashpop)
302 _arguments \
303 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
304 '*::stash:{_module_stash_colls}' && ret=0
305 ;;
306 (stashshow|stashrm)
307 _alternative 'avail-stashs:collections:{_module_stash_colls}' \
308 && ret=0
309 ;;
310 (clear)
311 _arguments \
312 '(-f --force)'{-f,--force}'[Skip confirmation dialog]' && ret=0
313 ;;
314 (restore)
315 _arguments \
316 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
317 '*::collection:{_module_saved_colls}' && ret=0
318 ;;
319 (save|saveshow|describe|saverm|disable|is-saved)
320 _alternative 'avail-colls:collections:{_module_saved_colls}' \
321 && ret=0
322 ;;
323 (rm|delete|remove|unload)
324 _arguments \
325 '--auto[Enable automated module handling mode]' \
326 '--no-auto[Disable automated module handling mode]' \
327 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
328 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
329 '*::modulefile:_module_loaded_mods' && ret=0
330 ;;
331 (purge)
332 _arguments \
333 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' && ret=0
334 ;;
335 (reload|update)
336 _arguments \
337 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' && ret=0
338 ;;
339 (reset)
340 _arguments \
341 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' && ret=0
342 ;;
343 (stash)
344 _arguments \
345 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' && ret=0
346 ;;
347 (switch|swap)
348 _arguments \
349 '--auto[Enable automated module handling mode]' \
350 '--no-auto[Disable automated module handling mode]' \
351 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
352 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
353 '--tag=[Apply tag to loading module]' \
354 '1:loaded modulefile:_module_loaded_mods' \
355 "2:modulefile:{_module_notloaded_mods $cur}" && ret=0
356 ;;
357 (unuse|is-used)
358 _alternative 'used-paths:modulepaths:{_module_used_paths}' \
359 && ret=0
360 ;;
361 (use)
362 _arguments \
363 '(-a --append)'{-a,--append}'[Append directory to MODULEPATH]' \
364 '(-p --prepend)'{-p,--prepend}'[Prepend directory to MODULEPATH]' \
365 '*:modulepath:_files -/' && ret=0
366 ;;
367 (cachebuild)
368 _arguments \
369 '*:modulepath:_files -/' && ret=0
370 ;;
371 (display|help|show|test|path|paths|is-loaded|info-loaded)
372 _arguments \
373 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
374 "*::modulefile:{_module_avail_mods $cur}" && ret=0
375 ;;
376 (is-avail)
377 _arguments \
378 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
379 "*::modulefile:{_module_avail_mods $cur}" && ret=0
380 ;;
381 (whatis)
382 _arguments \
383 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
384 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
385 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
386 "*::modulefile:{_module_avail_mods $cur}" && ret=0
387 ;;
388 (apropos|keyword|search)
389 _arguments \
390 '(-j --json)'{-j,--json}'[Display output in JSON format]' \
391 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
392 && ret=0
393 ;;
394 (append-path|prepend-path)
395 _arguments \
396 '(-d --delim)'{-d,--delim}'[Path element separator]' \
397 '--duplicates[Duplicate existing element]' \
398 && ret=0
399 ;;
400 (remove-path)
401 _arguments \
402 '(-d --delim)'{-d,--delim}'[Path element separator]' \
403 '--index[Remove path element with index]' \
404 && ret=0
405 ;;
406 (config)
407 _arguments \
408 '--dump-state[Report each state value of current Modules execution]' \
409 '--reset[Unset environment variable relative to configuration key]' \
410 '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 csh_limit domainname editor extended_default extra_siteconfig hide_auto_loaded home icase ignore_cache ignore_cache_subcmds ignore_user_rc ignored_dirs implicit_default implicit_requirement init_envvars info_extension linked_envvars list_output list_terse_output locked_configs logged_events logger mcookie_check mcookie_version_check ml modulepath_ignore nearly_forbidden_days non_exportable_tags pager paginate path_entry_reorder 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 siteconfig source_cache spider_indepth spider_output spider_terse_output sticky_purge tag_abbrev tag_color_name tcl_ext_lib tcl_linter term_background term_width unique_name_loaded unload_match_order variant_shortcut verbosity wa_277)' \
411 && ret=0
412 ;;
413 (edit)
414 _arguments \
415 "*::modulefile:{_module_avail_mods $cur}" && ret=0
416 ;;
417 (lint)
418 _arguments \
419 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
420 '(-a --all)'{-a,--all}'[Include hidden modules in search]' \
421 "*::modulefile:{_module_avail_mods $cur}" && ret=0
422 ;;
423 (mod-to-sh)
424 _arguments \
425 '--auto[Enable automated module handling mode]' \
426 '--no-auto[Disable automated module handling mode]' \
427 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
428 '(-i --icase)'{-i,--icase}'[Case insensitive match]' \
429 "*::modulefile:{_module_notloaded_mods $cur}" && ret=0
430 ;;
431 (source)
432 _arguments \
433 '--auto[Enable automated module handling mode]' \
434 '--no-auto[Disable automated module handling mode]' \
435 '(-f --force)'{-f,--force}'[By-pass dependency consistency]' \
436 '*:scriptfile:_files' && ret=0
437 ;;
438 esac
439 ;;
440 esac
441 }
442
443 _module "$@"
444
445 # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: