Bug 36329: Make POST /transfer_limits/batch honor BranchTransferLimitsType
[koha.git] / debian / koha-common.bash-completion
1 #!/bin/bash
2 #
3 # koha-common.bash-completion script for koha-* commands
4 #
5 # This file is part of Koha.
6 #
7 # Copyright 2013 Universidad Nacional de Cordoba
8 #                Tomas Cohen Arazi
9 #
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.
14 #
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.
18 #
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>.
21
22 _build_substract_switches()
23 {
24     local substract
25
26     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
27         if [[ ${COMP_WORDS[i]} == -* ]]; then
28             substract="$substract -e ${COMP_WORDS[i]}"
29         fi
30     done
31
32     echo "$substract"
33 }
34
35 _build_substract_instances()
36 {
37     local substract
38
39     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
40         substract="$substract -e ${COMP_WORDS[i]}"
41     done
42
43     echo "$substract"
44 }
45
46 _koha_single_instance()
47 {
48     local filter=$1
49
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=()
56     fi
57
58     return 0
59 }
60
61 _koha_list_cmd()
62 {
63     local filter=$1
64
65     local cur substract instancelist
66     _get_comp_words_by_ref cur
67
68     # Build a list of the already used words
69     substract=`_build_substract_instances`
70
71     if [[ "$substract" != "" ]]; then
72         instancelist=$( koha-list $filter | grep -v -x $substract )
73     else
74         instancelist=$( koha-list $filter )
75     fi
76
77     COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
78     return 0
79 }
80
81 _koha_email_disable()
82 {
83     _koha_list_cmd "--email"
84     return 0
85 }
86 complete -F _koha_email_disable koha-email-disable
87
88 _koha_email_enable()
89 {
90     _koha_list_cmd "--noemail"
91     return 0
92 }
93 complete -F _koha_email_enable koha-email-enable
94
95 _koha_sip_enabled_instances()
96 {
97     _koha_list_cmd "--sip"
98     return 0
99 }
100
101 _koha_sip_disabled()
102 {
103     _koha_list_cmd "--nosip"
104     return 0
105 }
106
107 _koha_disabled_instances()
108 {
109     _koha_list_cmd "--disabled"
110     return 0
111 }
112
113 _koha_enabled_instances()
114 {
115     _koha_list_cmd "--enabled"
116     return 0
117 }
118
119 # koha-enable autocompletes with disabled instances
120 complete -F _koha_disabled_instances koha-enable
121
122 # koha-disable autocompletes with enabled instances
123 complete -F _koha_enabled_instances koha-disable
124
125 # koha-mysql autocompletes with a single instance name
126 complete -F _koha_single_instance koha-mysql
127
128 _koha_list()
129 {
130     local cur opts substract
131
132     COMPREPLY=()
133     _get_comp_words_by_ref cur
134     opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h --elasticsearch --noelasticsearch"
135
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                 --elasticsearch)
145                     substract="$substract -e --noelasticsearch"; ;;
146                 --noelasticsearch)
147                     substract="$substract -e --elasticsearch"; ;;
148                 --email)
149                     substract="$substract -e --noemail"; ;;
150                 --noemail)
151                     substract="$substract -e --email"; ;;
152                 --plack)
153                     substract="$substract -e --noplack"; ;;
154                 --noplack)
155                     substract="$substract -e --plack"; ;;
156                 --sip)
157                     substract="$substract -e --nosip"; ;;
158                 --nosip)
159                     substract="$substract -e --sip"; ;;
160                 --help)
161                     substract="$substract -e -h"; ;;
162                 -h)
163                     substract="$substract -e --help"; ;;
164             esac
165             substract="$substract -e ${COMP_WORDS[i]}"
166         fi
167     done
168
169     if [[ "$substract" != "" ]]; then
170         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
171     fi
172
173     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
174
175     return 0
176 }
177 complete -F _koha_list koha-list
178
179 _koha_plack_instances()
180 {
181     _koha_list_cmd "--plack"
182     return 0
183 }
184
185 _koha_noplack_instances()
186 {
187     _koha_list_cmd "--noplack"
188     return 0
189 }
190
191 _koha-plack()
192 {
193     local cur opts substract
194
195     COMPREPLY=()
196     _get_comp_words_by_ref cur
197     opts="--start --stop --restart --enable --disable --quiet -q --help -h"
198
199     # Build a list of the already used option switches
200     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
201         if [[ ${COMP_WORDS[i]} == -* ]]; then
202             case ${COMP_WORDS[i]} in
203                 --start) _koha_plack_instances ; return 0 ;;
204                  --stop) _koha_plack_instances ; return 0 ;;
205               --restart) _koha_plack_instances ; return 0 ;;
206                --enable) _koha_noplack_instances ; return 0 ;;
207               --disable) _koha_plack_instances ; return 0 ;;
208                  --help) COMPREPLY=() ; return 0 ;; # no more completions
209                      -h) COMPREPLY=() ; return 0 ;; # no more completions
210                 --quiet) # filter the other quiet switches and go on
211                     substract="$substract -e -q"; ;;
212                 -q)      # filter the other quiet switches and go on
213                     substract="$substract -e --quiet"; ;;
214             esac
215             substract="$substract -e ${COMP_WORDS[i]}"
216         fi
217     done
218
219     if [[ "$substract" != "" ]]; then
220         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
221     fi
222
223     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
224
225     return 0
226 }
227 complete -F _koha-plack koha-plack
228
229 _koha-indexer()
230 {
231     local cur opts substract
232
233     COMPREPLY=()
234     _get_comp_words_by_ref cur
235     opts="--start --stop --restart --quiet -q --help -h"
236
237     # Build a list of the already used option switches
238     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
239         if [[ ${COMP_WORDS[i]} == -* ]]; then
240             case ${COMP_WORDS[i]} in
241                 --start) _koha_list_cmd ; return 0 ;;
242                  --stop) _koha_list_cmd ; return 0 ;;
243               --restart) _koha_list_cmd ; return 0 ;;
244                  --help) COMPREPLY=() ; return 0 ;; # no more completions
245                      -h) COMPREPLY=() ; return 0 ;; # no more completions
246                 --quiet) # filter the other quiet switches and go on
247                     substract="$substract -e -q"; ;;
248                 -q)      # filter the other quiet switches and go on
249                     substract="$substract -e --quiet"; ;;
250             esac
251             substract="$substract -e ${COMP_WORDS[i]}"
252         fi
253     done
254
255     if [[ "$substract" != "" ]]; then
256         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
257     fi
258
259     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
260
261     return 0
262 }
263 complete -F _koha-indexer koha-indexer
264 complete -F _koha-indexer koha-es-indexer
265
266 _koha-zebra()
267 {
268     local cur opts substract
269
270     COMPREPLY=()
271     _get_comp_words_by_ref cur
272     opts="--start --stop --restart --status --quiet -q --help -h"
273
274     # Build a list of the already used option switches
275     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
276         if [[ ${COMP_WORDS[i]} == -* ]]; then
277             case ${COMP_WORDS[i]} in
278                 --start) _koha_list_cmd ; return 0 ;;
279                  --stop) _koha_list_cmd ; return 0 ;;
280               --restart) _koha_list_cmd ; return 0 ;;
281                --status) _koha_list_cmd ; return 0 ;;
282                  --help) COMPREPLY=() ; return 0 ;; # no more completions
283                      -h) COMPREPLY=() ; return 0 ;; # no more completions
284                 --quiet) # filter the other quiet switches and go on
285                     substract="$substract -e -q"; ;;
286                 -q)      # filter the other quiet switches and go on
287                     substract="$substract -e --quiet"; ;;
288             esac
289             substract="$substract -e ${COMP_WORDS[i]}"
290         fi
291     done
292
293     if [[ "$substract" != "" ]]; then
294         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
295     fi
296
297     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
298
299     return 0
300 }
301 complete -F _koha-zebra koha-zebra
302
303
304 _koha-worker()
305 {
306     local cur opts substract
307
308     COMPREPLY=()
309     _get_comp_words_by_ref cur
310     opts="--start --stop --restart --status --quiet -q --help -h"
311
312     # Build a list of the already used option switches
313     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
314         if [[ ${COMP_WORDS[i]} == -* ]]; then
315             case ${COMP_WORDS[i]} in
316                 --start) _koha_list_cmd ; return 0 ;;
317                  --stop) _koha_list_cmd ; return 0 ;;
318               --restart) _koha_list_cmd ; return 0 ;;
319                --status) _koha_list_cmd ; return 0 ;;
320                  --help) COMPREPLY=() ; return 0 ;; # no more completions
321                      -h) COMPREPLY=() ; return 0 ;; # no more completions
322                 --quiet) # filter the other quiet switches and go on
323                     substract="$substract -e -q"; ;;
324                 -q)      # filter the other quiet switches and go on
325                     substract="$substract -e --quiet"; ;;
326             esac
327             substract="$substract -e ${COMP_WORDS[i]}"
328         fi
329     done
330
331     if [[ "$substract" != "" ]]; then
332         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
333     fi
334
335     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
336
337     return 0
338 }
339 complete -F _koha-worker koha-worker
340
341 _koha-sip()
342 {
343     local cur opts substract
344
345     COMPREPLY=()
346     _get_comp_words_by_ref cur
347     opts="--start --stop --restart --status --enable --verbose -v --help -h"
348
349     # Build a list of the already used option switches
350     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
351         if [[ ${COMP_WORDS[i]} == -* ]]; then
352             case ${COMP_WORDS[i]} in
353                 --start) _koha_sip_enabled_instances ; return 0 ;;
354                  --stop) _koha_sip_enabled_instances ; return 0 ;;
355               --restart) _koha_sip_enabled_instances ; return 0 ;;
356                --status) _koha_sip_enabled_instances ; return 0 ;;
357                --enable) _koha_sip_disabled ; return 0 ;;
358                  --help) COMPREPLY=() ; return 0 ;; # no more completions
359                      -h) COMPREPLY=() ; return 0 ;; # no more completions
360               --verbose) # filter the other quiet switches and go on
361                     substract="$substract -e -q"; ;;
362                 -v)      # filter the other quiet switches and go on
363                     substract="$substract -e --verbose"; ;;
364             esac
365             substract="$substract -e ${COMP_WORDS[i]}"
366         fi
367     done
368
369     if [[ "$substract" != "" ]]; then
370         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
371     fi
372
373     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
374
375     return 0
376 }
377 complete -F _koha-sip koha-sip
378
379 # Local variables:
380 # mode: shell-script
381 # sh-basic-offset: 4
382 # sh-indent-comment: t
383 # indent-tabs-mode: nil
384 # End:
385 # ex: ts=4 sw=4 et filetype=sh