3 # koha-common.bash-completion script for koha-* commands
5 # This file is part of Koha.
7 # Copyright 2013 Universidad Nacional de Cordoba
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
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()
26 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
27 if [[ ${COMP_WORDS[i]} == -* ]]; then
28 substract="$substract -e ${COMP_WORDS[i]}"
35 _build_substract_instances()
39 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
40 substract="$substract -e ${COMP_WORDS[i]}"
46 _koha_single_instance()
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 ) )
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 )
74 instancelist=$( koha-list $filter )
77 COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
83 _koha_list_cmd "--email"
86 complete -F _koha_email_disable koha-email-disable
90 _koha_list_cmd "--noemail"
93 complete -F _koha_email_enable koha-email-enable
95 _koha_sip_enabled_instances()
97 _koha_list_cmd "--sip"
103 _koha_list_cmd "--nosip"
107 _koha_disabled_instances()
109 _koha_list_cmd "--disabled"
113 _koha_enabled_instances()
115 _koha_list_cmd "--enabled"
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
130 local cur opts substract
133 _get_comp_words_by_ref cur
134 opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h --elasticsearch --noelasticsearch"
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
141 substract="$substract -e --enabled"; ;;
143 substract="$substract -e --disabled"; ;;
145 substract="$substract -e --noelasticsearch"; ;;
147 substract="$substract -e --elasticsearch"; ;;
149 substract="$substract -e --noemail"; ;;
151 substract="$substract -e --email"; ;;
153 substract="$substract -e --noplack"; ;;
155 substract="$substract -e --plack"; ;;
157 substract="$substract -e --nosip"; ;;
159 substract="$substract -e --sip"; ;;
161 substract="$substract -e -h"; ;;
163 substract="$substract -e --help"; ;;
165 substract="$substract -e ${COMP_WORDS[i]}"
169 if [[ "$substract" != "" ]]; then
170 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
173 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
177 complete -F _koha_list koha-list
179 _koha_plack_instances()
181 _koha_list_cmd "--plack"
185 _koha_noplack_instances()
187 _koha_list_cmd "--noplack"
193 local cur opts substract
196 _get_comp_words_by_ref cur
197 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
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"; ;;
215 substract="$substract -e ${COMP_WORDS[i]}"
219 if [[ "$substract" != "" ]]; then
220 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
223 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
227 complete -F _koha-plack koha-plack
231 local cur opts substract
234 _get_comp_words_by_ref cur
235 opts="--start --stop --restart --quiet -q --help -h"
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"; ;;
251 substract="$substract -e ${COMP_WORDS[i]}"
255 if [[ "$substract" != "" ]]; then
256 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
259 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
263 complete -F _koha-indexer koha-indexer
264 complete -F _koha-indexer koha-es-indexer
268 local cur opts substract
271 _get_comp_words_by_ref cur
272 opts="--start --stop --restart --status --quiet -q --help -h"
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"; ;;
289 substract="$substract -e ${COMP_WORDS[i]}"
293 if [[ "$substract" != "" ]]; then
294 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
297 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
301 complete -F _koha-zebra koha-zebra
306 local cur opts substract
309 _get_comp_words_by_ref cur
310 opts="--start --stop --restart --status --quiet -q --help -h"
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"; ;;
327 substract="$substract -e ${COMP_WORDS[i]}"
331 if [[ "$substract" != "" ]]; then
332 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
335 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
339 complete -F _koha-worker koha-worker
343 local cur opts substract
346 _get_comp_words_by_ref cur
347 opts="--start --stop --restart --status --enable --verbose -v --help -h"
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"; ;;
365 substract="$substract -e ${COMP_WORDS[i]}"
369 if [[ "$substract" != "" ]]; then
370 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
373 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
377 complete -F _koha-sip koha-sip
382 # sh-indent-comment: t
383 # indent-tabs-mode: nil
385 # ex: ts=4 sw=4 et filetype=sh