Bug 20402: Remove dependency on Mojo::Plugin::OAuth2::Server
[koha.git] / debian / koha-common.bash-completion
blob276cba07c963aa8f196d18fb4ced1fd107935e4e
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 autocomplete with sip-enabled instances
102 complete -F _koha_sip_enabled_instances koha-start-sip
103 complete -F _koha_sip_enabled_instances koha-restart-sip
104 complete -F _koha_sip_enabled_instances koha-stop-sip
106 _koha_sip_disabled()
108 _koha_list_cmd "--nosip"
109 return 0
112 # koha-enable-sip autocompletes with sip-disabled instances
113 complete -F _koha_sip_disabled koha-enable-sip
115 _koha_disabled_instances()
117 _koha_list_cmd "--disabled"
118 return 0
121 _koha_enabled_instances()
123 _koha_list_cmd "--enabled"
124 return 0
127 # koha-enable autocompletes with disabled instances
128 complete -F _koha_disabled_instances koha-enable
130 # koha-disable autocompletes with enabled instances
131 complete -F _koha_enabled_instances koha-disable
133 # koha-mysql autocompletes with a single instance name
134 complete -F _koha_single_instance koha-mysql
136 _koha_list()
138 local cur opts substract
140 COMPREPLY=()
141 _get_comp_words_by_ref cur
142 opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h"
144 # Build a list of the already used option switches
145 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
146 if [[ ${COMP_WORDS[i]} == -* ]]; then
147 case ${COMP_WORDS[i]} in
148 --disabled)
149 substract="$substract -e --enabled"; ;;
150 --enabled)
151 substract="$substract -e --disabled"; ;;
152 --email)
153 substract="$substract -e --noemail"; ;;
154 --noemail)
155 substract="$substract -e --email"; ;;
156 --plack)
157 substract="$substract -e --noplack"; ;;
158 --noplack)
159 substract="$substract -e --plack"; ;;
160 --sip)
161 substract="$substract -e --nosip"; ;;
162 --nosip)
163 substract="$substract -e --sip"; ;;
164 --help)
165 substract="$substract -e -h"; ;;
167 substract="$substract -e --help"; ;;
168 esac
169 substract="$substract -e ${COMP_WORDS[i]}"
171 done
173 if [[ "$substract" != "" ]]; then
174 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
177 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
179 return 0
181 complete -F _koha_list koha-list
183 _koha_plack_instances()
185 _koha_list_cmd "--plack"
186 return 0
189 _koha_noplack_instances()
191 _koha_list_cmd "--noplack"
192 return 0
195 _koha-plack()
197 local cur opts substract
199 COMPREPLY=()
200 _get_comp_words_by_ref cur
201 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
203 # Build a list of the already used option switches
204 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
205 if [[ ${COMP_WORDS[i]} == -* ]]; then
206 case ${COMP_WORDS[i]} in
207 --start) _koha_plack_instances ; return 0 ;;
208 --stop) _koha_plack_instances ; return 0 ;;
209 --restart) _koha_plack_instances ; return 0 ;;
210 --enable) _koha_noplack_instances ; return 0 ;;
211 --disable) _koha_plack_instances ; return 0 ;;
212 --help) COMPREPLY=() ; return 0 ;; # no more completions
213 -h) COMPREPLY=() ; return 0 ;; # no more completions
214 --quiet) # filter the other quiet switches and go on
215 substract="$substract -e -q"; ;;
216 -q) # filter the other quiet switches and go on
217 substract="$substract -e --quiet"; ;;
218 esac
219 substract="$substract -e ${COMP_WORDS[i]}"
221 done
223 if [[ "$substract" != "" ]]; then
224 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
227 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
229 return 0
231 complete -F _koha-plack koha-plack
233 _koha-indexer()
235 local cur opts substract
237 COMPREPLY=()
238 _get_comp_words_by_ref cur
239 opts="--start --stop --restart --quiet -q --help -h"
241 # Build a list of the already used option switches
242 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
243 if [[ ${COMP_WORDS[i]} == -* ]]; then
244 case ${COMP_WORDS[i]} in
245 --start) _koha_list_cmd ; return 0 ;;
246 --stop) _koha_list_cmd ; return 0 ;;
247 --restart) _koha_list_cmd ; return 0 ;;
248 --help) COMPREPLY=() ; return 0 ;; # no more completions
249 -h) COMPREPLY=() ; return 0 ;; # no more completions
250 --quiet) # filter the other quiet switches and go on
251 substract="$substract -e -q"; ;;
252 -q) # filter the other quiet switches and go on
253 substract="$substract -e --quiet"; ;;
254 esac
255 substract="$substract -e ${COMP_WORDS[i]}"
257 done
259 if [[ "$substract" != "" ]]; then
260 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
263 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
265 return 0
267 complete -F _koha-indexer koha-indexer
269 _koha-zebra()
271 local cur opts substract
273 COMPREPLY=()
274 _get_comp_words_by_ref cur
275 opts="--start --stop --restart --status --quiet -q --help -h"
277 # Build a list of the already used option switches
278 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
279 if [[ ${COMP_WORDS[i]} == -* ]]; then
280 case ${COMP_WORDS[i]} in
281 --start) _koha_list_cmd ; return 0 ;;
282 --stop) _koha_list_cmd ; return 0 ;;
283 --restart) _koha_list_cmd ; return 0 ;;
284 --status) _koha_list_cmd ; return 0 ;;
285 --help) COMPREPLY=() ; return 0 ;; # no more completions
286 -h) COMPREPLY=() ; return 0 ;; # no more completions
287 --quiet) # filter the other quiet switches and go on
288 substract="$substract -e -q"; ;;
289 -q) # filter the other quiet switches and go on
290 substract="$substract -e --quiet"; ;;
291 esac
292 substract="$substract -e ${COMP_WORDS[i]}"
294 done
296 if [[ "$substract" != "" ]]; then
297 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
300 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
302 return 0
304 complete -F _koha-zebra koha-zebra
306 # Local variables:
307 # mode: shell-script
308 # sh-basic-offset: 4
309 # sh-indent-comment: t
310 # indent-tabs-mode: nil
311 # End:
312 # ex: ts=4 sw=4 et filetype=sh