Bug 24080: DBRev 19.12.00.004
[koha.git] / debian / koha-common.bash-completion
blobb40ae47a3a7ea12a31f7715bdced74b647fde8e1
1 #!/bin/bash
3 # koha-common.bash-completion script for koha-* commands
5 # This file is part of Koha.
7 # Copyright 2013 Universidad Nacional de Cordoba
8 # Tomas Cohen Arazi
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 3 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, see <http://www.gnu.org/licenses>.
22 _build_substract_switches()
24 local substract
26 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
27 if [[ ${COMP_WORDS[i]} == -* ]]; then
28 substract="$substract -e ${COMP_WORDS[i]}"
30 done
32 echo "$substract"
35 _build_substract_instances()
37 local substract
39 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
40 substract="$substract -e ${COMP_WORDS[i]}"
41 done
43 echo "$substract"
46 _koha_single_instance()
48 local filter=$1
50 cur=${COMP_WORDS[COMP_CWORD]}
51 prev=${COMP_WORDS[COMP_CWORD-1]}
52 if [ $COMP_CWORD -eq 1 ]; then
53 COMPREPLY=( $( compgen -W "$(koha-list $filter)" $cur ) )
54 else
55 COMPREPLY=()
58 return 0
61 _koha_list_cmd()
63 local filter=$1
65 local cur substract instancelist
66 _get_comp_words_by_ref cur
68 # Build a list of the already used words
69 substract=`_build_substract_instances`
71 if [[ "$substract" != "" ]]; then
72 instancelist=$( koha-list $filter | grep -v -x $substract )
73 else
74 instancelist=$( koha-list $filter )
77 COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
78 return 0
81 _koha_email_disable()
83 _koha_list_cmd "--email"
84 return 0
86 complete -F _koha_email_disable koha-email-disable
88 _koha_email_enable()
90 _koha_list_cmd "--noemail"
91 return 0
93 complete -F _koha_email_enable koha-email-enable
95 _koha_sip_enabled_instances()
97 _koha_list_cmd "--sip"
98 return 0
101 _koha_sip_disabled()
103 _koha_list_cmd "--nosip"
104 return 0
107 _koha_disabled_instances()
109 _koha_list_cmd "--disabled"
110 return 0
113 _koha_enabled_instances()
115 _koha_list_cmd "--enabled"
116 return 0
119 # koha-enable autocompletes with disabled instances
120 complete -F _koha_disabled_instances koha-enable
122 # koha-disable autocompletes with enabled instances
123 complete -F _koha_enabled_instances koha-disable
125 # koha-mysql autocompletes with a single instance name
126 complete -F _koha_single_instance koha-mysql
128 _koha_list()
130 local cur opts substract
132 COMPREPLY=()
133 _get_comp_words_by_ref cur
134 opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h"
136 # Build a list of the already used option switches
137 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
138 if [[ ${COMP_WORDS[i]} == -* ]]; then
139 case ${COMP_WORDS[i]} in
140 --disabled)
141 substract="$substract -e --enabled"; ;;
142 --enabled)
143 substract="$substract -e --disabled"; ;;
144 --email)
145 substract="$substract -e --noemail"; ;;
146 --noemail)
147 substract="$substract -e --email"; ;;
148 --plack)
149 substract="$substract -e --noplack"; ;;
150 --noplack)
151 substract="$substract -e --plack"; ;;
152 --sip)
153 substract="$substract -e --nosip"; ;;
154 --nosip)
155 substract="$substract -e --sip"; ;;
156 --help)
157 substract="$substract -e -h"; ;;
159 substract="$substract -e --help"; ;;
160 esac
161 substract="$substract -e ${COMP_WORDS[i]}"
163 done
165 if [[ "$substract" != "" ]]; then
166 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
169 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
171 return 0
173 complete -F _koha_list koha-list
175 _koha_plack_instances()
177 _koha_list_cmd "--plack"
178 return 0
181 _koha_noplack_instances()
183 _koha_list_cmd "--noplack"
184 return 0
187 _koha-plack()
189 local cur opts substract
191 COMPREPLY=()
192 _get_comp_words_by_ref cur
193 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
195 # Build a list of the already used option switches
196 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
197 if [[ ${COMP_WORDS[i]} == -* ]]; then
198 case ${COMP_WORDS[i]} in
199 --start) _koha_plack_instances ; return 0 ;;
200 --stop) _koha_plack_instances ; return 0 ;;
201 --restart) _koha_plack_instances ; return 0 ;;
202 --enable) _koha_noplack_instances ; return 0 ;;
203 --disable) _koha_plack_instances ; return 0 ;;
204 --help) COMPREPLY=() ; return 0 ;; # no more completions
205 -h) COMPREPLY=() ; return 0 ;; # no more completions
206 --quiet) # filter the other quiet switches and go on
207 substract="$substract -e -q"; ;;
208 -q) # filter the other quiet switches and go on
209 substract="$substract -e --quiet"; ;;
210 esac
211 substract="$substract -e ${COMP_WORDS[i]}"
213 done
215 if [[ "$substract" != "" ]]; then
216 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
219 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
221 return 0
223 complete -F _koha-plack koha-plack
225 _koha-indexer()
227 local cur opts substract
229 COMPREPLY=()
230 _get_comp_words_by_ref cur
231 opts="--start --stop --restart --quiet -q --help -h"
233 # Build a list of the already used option switches
234 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
235 if [[ ${COMP_WORDS[i]} == -* ]]; then
236 case ${COMP_WORDS[i]} in
237 --start) _koha_list_cmd ; return 0 ;;
238 --stop) _koha_list_cmd ; return 0 ;;
239 --restart) _koha_list_cmd ; return 0 ;;
240 --help) COMPREPLY=() ; return 0 ;; # no more completions
241 -h) COMPREPLY=() ; return 0 ;; # no more completions
242 --quiet) # filter the other quiet switches and go on
243 substract="$substract -e -q"; ;;
244 -q) # filter the other quiet switches and go on
245 substract="$substract -e --quiet"; ;;
246 esac
247 substract="$substract -e ${COMP_WORDS[i]}"
249 done
251 if [[ "$substract" != "" ]]; then
252 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
255 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
257 return 0
259 complete -F _koha-indexer koha-indexer
261 _koha-zebra()
263 local cur opts substract
265 COMPREPLY=()
266 _get_comp_words_by_ref cur
267 opts="--start --stop --restart --status --quiet -q --help -h"
269 # Build a list of the already used option switches
270 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
271 if [[ ${COMP_WORDS[i]} == -* ]]; then
272 case ${COMP_WORDS[i]} in
273 --start) _koha_list_cmd ; return 0 ;;
274 --stop) _koha_list_cmd ; return 0 ;;
275 --restart) _koha_list_cmd ; return 0 ;;
276 --status) _koha_list_cmd ; return 0 ;;
277 --help) COMPREPLY=() ; return 0 ;; # no more completions
278 -h) COMPREPLY=() ; return 0 ;; # no more completions
279 --quiet) # filter the other quiet switches and go on
280 substract="$substract -e -q"; ;;
281 -q) # filter the other quiet switches and go on
282 substract="$substract -e --quiet"; ;;
283 esac
284 substract="$substract -e ${COMP_WORDS[i]}"
286 done
288 if [[ "$substract" != "" ]]; then
289 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
292 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
294 return 0
296 complete -F _koha-zebra koha-zebra
298 _koha-sip()
300 local cur opts substract
302 COMPREPLY=()
303 _get_comp_words_by_ref cur
304 opts="--start --stop --restart --status --enable --verbose -v --help -h"
306 # Build a list of the already used option switches
307 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
308 if [[ ${COMP_WORDS[i]} == -* ]]; then
309 case ${COMP_WORDS[i]} in
310 --start) _koha_sip_enabled_instances ; return 0 ;;
311 --stop) _koha_sip_enabled_instances ; return 0 ;;
312 --restart) _koha_sip_enabled_instances ; return 0 ;;
313 --status) _koha_sip_enabled_instances ; return 0 ;;
314 --enable) _koha_sip_disabled ; return 0 ;;
315 --help) COMPREPLY=() ; return 0 ;; # no more completions
316 -h) COMPREPLY=() ; return 0 ;; # no more completions
317 --verbose) # filter the other quiet switches and go on
318 substract="$substract -e -q"; ;;
319 -v) # filter the other quiet switches and go on
320 substract="$substract -e --verbose"; ;;
321 esac
322 substract="$substract -e ${COMP_WORDS[i]}"
324 done
326 if [[ "$substract" != "" ]]; then
327 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
330 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
332 return 0
334 complete -F _koha-sip koha-sip
336 # Local variables:
337 # mode: shell-script
338 # sh-basic-offset: 4
339 # sh-indent-comment: t
340 # indent-tabs-mode: nil
341 # End:
342 # ex: ts=4 sw=4 et filetype=sh