3 # koha-core.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
267 local cur opts substract
270 _get_comp_words_by_ref cur
271 opts="--start --stop --restart --status --quiet -q --help -h"
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"; ;;
288 substract="$substract -e ${COMP_WORDS[i]}"
292 if [[ "$substract" != "" ]]; then
293 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
296 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
300 complete -F _koha-zebra koha-zebra
304 local cur opts substract
307 _get_comp_words_by_ref cur
308 opts="--start --stop --restart --status --enable --verbose -v --help -h"
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"; ;;
326 substract="$substract -e ${COMP_WORDS[i]}"
330 if [[ "$substract" != "" ]]; then
331 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
334 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
338 complete -F _koha-sip koha-sip
343 # sh-indent-comment: t
344 # indent-tabs-mode: nil
346 # ex: ts=4 sw=4 et filetype=sh