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"
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
108 _koha_list_cmd "--nosip"
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"
121 _koha_enabled_instances()
123 _koha_list_cmd "--enabled"
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-*-zebra autocomplete with enabled instances
134 complete -F _koha_enabled_instances koha-start-zebra
135 complete -F _koha_enabled_instances koha-restart-zebra
136 complete -F _koha_enabled_instances koha-stop-zebra
138 # koha-mysql autocompletes with a single instance name
139 complete -F _koha_single_instance koha-mysql
143 local cur opts substract
146 _get_comp_words_by_ref cur
147 opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h"
149 # Build a list of the already used option switches
150 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
151 if [[ ${COMP_WORDS[i]} == -* ]]; then
152 case ${COMP_WORDS[i]} in
154 substract="$substract -e --enabled"; ;;
156 substract="$substract -e --disabled"; ;;
158 substract="$substract -e --noemail"; ;;
160 substract="$substract -e --email"; ;;
162 substract="$substract -e --noplack"; ;;
164 substract="$substract -e --plack"; ;;
166 substract="$substract -e --nosip"; ;;
168 substract="$substract -e --sip"; ;;
170 substract="$substract -e -h"; ;;
172 substract="$substract -e --help"; ;;
174 substract="$substract -e ${COMP_WORDS[i]}"
178 if [[ "$substract" != "" ]]; then
179 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
182 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
186 complete -F _koha_list koha-list
188 _koha_plack_instances()
190 _koha_list_cmd "--plack"
194 _koha_noplack_instances()
196 _koha_list_cmd "--noplack"
202 local cur opts substract
205 _get_comp_words_by_ref cur
206 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
208 # Build a list of the already used option switches
209 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
210 if [[ ${COMP_WORDS[i]} == -* ]]; then
211 case ${COMP_WORDS[i]} in
212 --start) _koha_plack_instances ; return 0 ;;
213 --stop) _koha_plack_instances ; return 0 ;;
214 --restart) _koha_plack_instances ; return 0 ;;
215 --enable) _koha_noplack_instances ; return 0 ;;
216 --disable) _koha_plack_instances ; return 0 ;;
217 --help) COMPREPLY=() ; return 0 ;; # no more completions
218 -h) COMPREPLY=() ; return 0 ;; # no more completions
219 --quiet) # filter the other quiet switches and go on
220 substract="$substract -e -q"; ;;
221 -q) # filter the other quiet switches and go on
222 substract="$substract -e --quiet"; ;;
224 substract="$substract -e ${COMP_WORDS[i]}"
228 if [[ "$substract" != "" ]]; then
229 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
232 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
236 complete -F _koha-plack koha-plack
240 local cur opts substract
243 _get_comp_words_by_ref cur
244 opts="--start --stop --restart --quiet -q --help -h"
246 # Build a list of the already used option switches
247 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
248 if [[ ${COMP_WORDS[i]} == -* ]]; then
249 case ${COMP_WORDS[i]} in
250 --start) _koha_list_cmd ; return 0 ;;
251 --stop) _koha_list_cmd ; return 0 ;;
252 --restart) _koha_list_cmd ; return 0 ;;
253 --help) COMPREPLY=() ; return 0 ;; # no more completions
254 -h) COMPREPLY=() ; return 0 ;; # no more completions
255 --quiet) # filter the other quiet switches and go on
256 substract="$substract -e -q"; ;;
257 -q) # filter the other quiet switches and go on
258 substract="$substract -e --quiet"; ;;
260 substract="$substract -e ${COMP_WORDS[i]}"
264 if [[ "$substract" != "" ]]; then
265 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
268 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
272 complete -F _koha-indexer koha-indexer
276 local cur opts substract
279 _get_comp_words_by_ref cur
280 opts="--start --stop --restart --status --quiet -q --help -h"
282 # Build a list of the already used option switches
283 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
284 if [[ ${COMP_WORDS[i]} == -* ]]; then
285 case ${COMP_WORDS[i]} in
286 --start) _koha_list_cmd ; return 0 ;;
287 --stop) _koha_list_cmd ; return 0 ;;
288 --restart) _koha_list_cmd ; return 0 ;;
289 --status) _koha_list_cmd ; return 0 ;;
290 --help) COMPREPLY=() ; return 0 ;; # no more completions
291 -h) COMPREPLY=() ; return 0 ;; # no more completions
292 --quiet) # filter the other quiet switches and go on
293 substract="$substract -e -q"; ;;
294 -q) # filter the other quiet switches and go on
295 substract="$substract -e --quiet"; ;;
297 substract="$substract -e ${COMP_WORDS[i]}"
301 if [[ "$substract" != "" ]]; then
302 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
305 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
309 complete -F _koha-zebra koha-zebra
314 # sh-indent-comment: t
315 # indent-tabs-mode: nil
317 # ex: ts=4 sw=4 et filetype=sh