Debian Codegraph @

init/bash_completion.in

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # shellcheck shell=bash
2 #
3 # Bash commandline completion
4 #
5 _module_comgen_words_and_files() {
6 local k=0
7 local setnospace=1
8 # do not append space to word completed if it is a directory (ends with /)
9 for val in $(compgen -W "$1" -- "$2"); do
10 if [ $setnospace -eq 1 ] && [ "${val: -1:1}" = '/' ]; then
11 # Bash >=4.0 is required for compopt
12 type compopt &>/dev/null && compopt -o nospace
13 setnospace=0
14 fi
15 COMPREPLY[k++]="$val"
16 done
17 }
18
19 _module_avail() {
20 local cur="${1:-}"
21 # skip avail call if word currently being completed is an option keyword
22 if [ -z "$cur" ] || [ "${cur:0:1}" != '-' ]; then
23 module avail --color=never -s -t -S --no-indepth -o 'alias:indesym' "$cur" 2>&1
24 fi
25 }
26
27 _module_spider() {
28 local cur="${1:-}"
29 # skip spider call if word currently being completed is an option keyword
30 if [ -z "$cur" ] || [ "${cur:0:1}" != '-' ]; then
31 module spider --color=never -s -t -S --no-indepth -o 'alias:indesym' "$cur" 2>&1
32 fi
33 }
34
35 _module_savelist() {
36 module savelist --color=never -s -t 2>&1 | sed '
37 /No named collection\.$/d;
38 /Named collection list$/d;
39 /:$/d;'
40 }
41
42 _module_stashlist() {
43 module stashlist --color=never -s -t 2>&1 | sed '
44 /No stash collection\.$/d;
45 /Stash collection list$/d;
46 /:$/d;'
47 }
48
49 _module_not_yet_loaded() {
50 _module_avail "${1:-}" | sort | @SED_ERE@ "\%^(${LOADEDMODULES//:/|})$%d"
51 }
52
53 _module_long_arg_list() {
54 local cur="$1" i
55
56 if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]]
57 then
58 _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur"
59 return
60 fi
61 for ((i = COMP_CWORD - 1; i > 0; i--))
62 do case ${COMP_WORDS[$i]} in
63 add|load)
64 _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur"
65 break;;
66 rm|del|remove|unload|switch|swap)
67 COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") )
68 break;;
69 esac
70 done
71 }
72
73 _module() {
74 local cur="$2" prev="$3"
75
76 COMPREPLY=()
77
78 case "$prev" in
79 add|add-any|load|load-any|try-add|try-load)
80 _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
81 avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_avail "$cur")" "$cur";;
82 spider) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_spider "$cur")" "$cur";;
83 edit) _module_comgen_words_and_files "$(_module_avail "$cur")" "$cur";;
84 aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );;
85 list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );;
86 stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );;
87 stashpop|stashshow|stashrm)
88 COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );;
89 clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );;
90 restore|save|saveshow|describe|saverm|disable|is-saved)
91 COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
92 rm|del|remove|unload)
93 COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
94 switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
95 unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );;
96 use|-a|--append|cachebuild) ;; # let readline handle the completion
97 display|help|show|test|path|paths|is-loaded|info-loaded)
98 _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";;
99 is-avail)
100 _module_comgen_words_and_files "@comp_isavail_opts@ $(_module_avail "$cur")" "$cur";;
101 lint)
102 _module_comgen_words_and_files "@comp_lint_opts@ $(_module_avail "$cur")" "$cur";;
103 mod-to-sh)
104 _module_comgen_words_and_files "@comp_modtosh_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
105 whatis)
106 _module_comgen_words_and_files "@comp_whatis_opts@ $(_module_avail "$cur")" "$cur";;
107 apropos|keyword|search)
108 COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
109 config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
110 -h|--help|-V|--version|--dumpname|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|cacheclear|update)
111 ;;
112 append-path|prepend-path)
113 COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
114 remove-path)
115 COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") );;
116 initadd|initclear|initlist|initprepend|initrm)
117 ;;
118 *) if test "$COMP_CWORD" -gt 2
119 then
120 _module_long_arg_list "$cur"
121 else
122 case "$cur" in
123 # The mappings below are optional abbreviations for convenience
124 ls) COMPREPLY=( "list" );; # map ls -> list
125 sw*) COMPREPLY=( "switch" );;
126
127 -*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );;
128 *) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") );;
129 esac
130 fi;;
131 esac
132 }
133
134 # define completion for ml command if command exists
135 if type -t ml >/dev/null; then
136 _ml() {
137 local cur="$2" prev="$3"
138
139 COMPREPLY=()
140
141 case "$prev" in
142 add|add-any|load|load-any|try-add|try-load)
143 _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
144 avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_avail "$cur")" "$cur";;
145 spider) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_spider "$cur")" "$cur";;
146 edit) _module_comgen_words_and_files "$(_module_avail "$cur")" "$cur";;
147 aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );;
148 list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );;
149 stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );;
150 stashpop|stashshow|stashrm)
151 COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );;
152 clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );;
153 restore|save|saveshow|describe|saverm|disable|is-saved)
154 COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
155 rm|del|remove|unload)
156 COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
157 switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
158 unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );;
159 use|-a|--append|cachebuild) ;; # let readline handle the completion
160 display|help|show|test|path|paths|is-loaded|info-loaded)
161 _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";;
162 is-avail)
163 _module_comgen_words_and_files "@comp_isavail_opts@ $(_module_avail "$cur")" "$cur";;
164 lint)
165 _module_comgen_words_and_files "@comp_lint_opts@ $(_module_avail "$cur")" "$cur";;
166 mod-to-sh)
167 _module_comgen_words_and_files "@comp_modtosh_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
168 whatis)
169 _module_comgen_words_and_files "@comp_whatis_opts@ $(_module_avail "$cur")" "$cur";;
170 apropos|keyword|search)
171 COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
172 config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
173 -h|--help|-V|--version|--dumpname|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|cacheclear|update)
174 ;;
175 append-path|prepend-path)
176 COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
177 remove-path)
178 COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") );;
179 initadd|initclear|initlist|initprepend|initrm)
180 ;;
181 *) if test "$COMP_CWORD" -gt 2
182 then
183 _module_long_arg_list "$cur"
184 else
185 case "$cur" in
186 # The mappings below are optional abbreviations for convenience
187 ls) COMPREPLY=( "list" );; # map ls -> list
188 sw*) COMPREPLY=( "switch" );;
189
190 -*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") )
191 loaded_modules=""
192 for i in ${LOADEDMODULES//:/ }; do
193 loaded_modules+="-${i} "
194 done
195 COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );;
196 *) _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur"
197 COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") )
198 loaded_modules=""
199 for i in ${LOADEDMODULES//:/ }; do
200 loaded_modules+="-${i} "
201 done
202 COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );;
203 esac
204 fi;;
205 esac
206 }
207 complete -o default -F _ml ml
208 fi
209 complete -o default -F _module module