Bug 33108: koha-es-indexer added
[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"
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                 --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"; ;;
158                 -h)
159                     substract="$substract -e --help"; ;;
160             esac
161             substract="$substract -e ${COMP_WORDS[i]}"
162         fi
163     done
164
165     if [[ "$substract" != "" ]]; then
166         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
167     fi
168
169     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
170
171     return 0
172 }
173 complete -F _koha_list koha-list
174
175 _koha_plack_instances()
176 {
177     _koha_list_cmd "--plack"
178     return 0
179 }
180
181 _koha_noplack_instances()
182 {
183     _koha_list_cmd "--noplack"
184     return 0
185 }
186
187 _koha-plack()
188 {
189     local cur opts substract
190
191     COMPREPLY=()
192     _get_comp_words_by_ref cur
193     opts="--start --stop --restart --enable --disable --quiet -q --help -h"
194
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]}"
212         fi
213     done
214
215     if [[ "$substract" != "" ]]; then
216         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
217     fi
218
219     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
220
221     return 0
222 }
223 complete -F _koha-plack koha-plack
224
225 _koha-indexer()
226 {
227     local cur opts substract
228
229     COMPREPLY=()
230     _get_comp_words_by_ref cur
231     opts="--start --stop --restart --quiet -q --help -h"
232
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]}"
248         fi
249     done
250
251     if [[ "$substract" != "" ]]; then
252         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
253     fi
254
255     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
256
257     return 0
258 }
259 complete -F _koha-indexer koha-indexer
260 complete -F _koha-indexer koha-es-indexer
261
262 _koha-zebra()
263 {
264     local cur opts substract
265
266     COMPREPLY=()
267     _get_comp_words_by_ref cur
268     opts="--start --stop --restart --status --quiet -q --help -h"
269
270     # Build a list of the already used option switches
271     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
272         if [[ ${COMP_WORDS[i]} == -* ]]; then
273             case ${COMP_WORDS[i]} in
274                 --start) _koha_list_cmd ; return 0 ;;
275                  --stop) _koha_list_cmd ; return 0 ;;
276               --restart) _koha_list_cmd ; return 0 ;;
277                --status) _koha_list_cmd ; return 0 ;;
278                  --help) COMPREPLY=() ; return 0 ;; # no more completions
279                      -h) COMPREPLY=() ; return 0 ;; # no more completions
280                 --quiet) # filter the other quiet switches and go on
281                     substract="$substract -e -q"; ;;
282                 -q)      # filter the other quiet switches and go on
283                     substract="$substract -e --quiet"; ;;
284             esac
285             substract="$substract -e ${COMP_WORDS[i]}"
286         fi
287     done
288
289     if [[ "$substract" != "" ]]; then
290         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
291     fi
292
293     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
294
295     return 0
296 }
297 complete -F _koha-zebra koha-zebra
298
299
300 _koha-worker()
301 {
302     local cur opts substract
303
304     COMPREPLY=()
305     _get_comp_words_by_ref cur
306     opts="--start --stop --restart --status --quiet -q --help -h"
307
308     # Build a list of the already used option switches
309     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
310         if [[ ${COMP_WORDS[i]} == -* ]]; then
311             case ${COMP_WORDS[i]} in
312                 --start) _koha_list_cmd ; return 0 ;;
313                  --stop) _koha_list_cmd ; return 0 ;;
314               --restart) _koha_list_cmd ; return 0 ;;
315                --status) _koha_list_cmd ; return 0 ;;
316                  --help) COMPREPLY=() ; return 0 ;; # no more completions
317                      -h) COMPREPLY=() ; return 0 ;; # no more completions
318                 --quiet) # filter the other quiet switches and go on
319                     substract="$substract -e -q"; ;;
320                 -q)      # filter the other quiet switches and go on
321                     substract="$substract -e --quiet"; ;;
322             esac
323             substract="$substract -e ${COMP_WORDS[i]}"
324         fi
325     done
326
327     if [[ "$substract" != "" ]]; then
328         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
329     fi
330
331     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
332
333     return 0
334 }
335 complete -F _koha-worker koha-worker
336
337 _koha-sip()
338 {
339     local cur opts substract
340
341     COMPREPLY=()
342     _get_comp_words_by_ref cur
343     opts="--start --stop --restart --status --enable --verbose -v --help -h"
344
345     # Build a list of the already used option switches
346     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
347         if [[ ${COMP_WORDS[i]} == -* ]]; then
348             case ${COMP_WORDS[i]} in
349                 --start) _koha_sip_enabled_instances ; return 0 ;;
350                  --stop) _koha_sip_enabled_instances ; return 0 ;;
351               --restart) _koha_sip_enabled_instances ; return 0 ;;
352                --status) _koha_sip_enabled_instances ; return 0 ;;
353                --enable) _koha_sip_disabled ; return 0 ;;
354                  --help) COMPREPLY=() ; return 0 ;; # no more completions
355                      -h) COMPREPLY=() ; return 0 ;; # no more completions
356               --verbose) # filter the other quiet switches and go on
357                     substract="$substract -e -q"; ;;
358                 -v)      # filter the other quiet switches and go on
359                     substract="$substract -e --verbose"; ;;
360             esac
361             substract="$substract -e ${COMP_WORDS[i]}"
362         fi
363     done
364
365     if [[ "$substract" != "" ]]; then
366         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
367     fi
368
369     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
370
371     return 0
372 }
373 complete -F _koha-sip koha-sip
374
375 # Local variables:
376 # mode: shell-script
377 # sh-basic-offset: 4
378 # sh-indent-comment: t
379 # indent-tabs-mode: nil
380 # End:
381 # ex: ts=4 sw=4 et filetype=sh