Bug 35492: Open holds tab by default on opac-user.pl after suspending a hold
[koha.git] / debian / koha-core.bash-completion
1 #!/bin/bash
2 #
3 # koha-core.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
265 _koha-zebra()
266 {
267     local cur opts substract
268
269     COMPREPLY=()
270     _get_comp_words_by_ref cur
271     opts="--start --stop --restart --status --quiet -q --help -h"
272
273     # Build a list of the already used option switches
274     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
275         if [[ ${COMP_WORDS[i]} == -* ]]; then
276             case ${COMP_WORDS[i]} in
277                 --start) _koha_list_cmd ; return 0 ;;
278                  --stop) _koha_list_cmd ; return 0 ;;
279               --restart) _koha_list_cmd ; return 0 ;;
280                --status) _koha_list_cmd ; return 0 ;;
281                  --help) COMPREPLY=() ; return 0 ;; # no more completions
282                      -h) COMPREPLY=() ; return 0 ;; # no more completions
283                 --quiet) # filter the other quiet switches and go on
284                     substract="$substract -e -q"; ;;
285                 -q)      # filter the other quiet switches and go on
286                     substract="$substract -e --quiet"; ;;
287             esac
288             substract="$substract -e ${COMP_WORDS[i]}"
289         fi
290     done
291
292     if [[ "$substract" != "" ]]; then
293         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
294     fi
295
296     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
297
298     return 0
299 }
300 complete -F _koha-zebra koha-zebra
301
302 _koha-sip()
303 {
304     local cur opts substract
305
306     COMPREPLY=()
307     _get_comp_words_by_ref cur
308     opts="--start --stop --restart --status --enable --verbose -v --help -h"
309
310     # Build a list of the already used option switches
311     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
312         if [[ ${COMP_WORDS[i]} == -* ]]; then
313             case ${COMP_WORDS[i]} in
314                 --start) _koha_sip_enabled_instances ; return 0 ;;
315                  --stop) _koha_sip_enabled_instances ; return 0 ;;
316               --restart) _koha_sip_enabled_instances ; return 0 ;;
317                --status) _koha_sip_enabled_instances ; return 0 ;;
318                --enable) _koha_sip_disabled ; return 0 ;;
319                  --help) COMPREPLY=() ; return 0 ;; # no more completions
320                      -h) COMPREPLY=() ; return 0 ;; # no more completions
321               --verbose) # filter the other quiet switches and go on
322                     substract="$substract -e -q"; ;;
323                 -v)      # filter the other quiet switches and go on
324                     substract="$substract -e --verbose"; ;;
325             esac
326             substract="$substract -e ${COMP_WORDS[i]}"
327         fi
328     done
329
330     if [[ "$substract" != "" ]]; then
331         opts=$( echo $opts | sed -e 's/ /\n/g'  | grep -v -x $substract )
332     fi
333
334     COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
335
336     return 0
337 }
338 complete -F _koha-sip koha-sip
339
340 # Local variables:
341 # mode: shell-script
342 # sh-basic-offset: 4
343 # sh-indent-comment: t
344 # indent-tabs-mode: nil
345 # End:
346 # ex: ts=4 sw=4 et filetype=sh