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"
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 --noemail"; ;;
147 substract="$substract -e --email"; ;;
149 substract="$substract -e --noplack"; ;;
151 substract="$substract -e --plack"; ;;
153 substract="$substract -e --nosip"; ;;
155 substract="$substract -e --sip"; ;;
157 substract="$substract -e -h"; ;;
159 substract="$substract -e --help"; ;;
161 substract="$substract -e ${COMP_WORDS[i]}"
165 if [[ "$substract" != "" ]]; then
166 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
169 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
173 complete -F _koha_list koha-list
175 _koha_plack_instances()
177 _koha_list_cmd "--plack"
181 _koha_noplack_instances()
183 _koha_list_cmd "--noplack"
189 local cur opts substract
192 _get_comp_words_by_ref cur
193 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
195 # Build a list of the already used option switches
196 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
197 if [[ ${COMP_WORDS[i]} == -* ]]; then
198 case ${COMP_WORDS[i]} in
199 --start) _koha_plack_instances ; return 0 ;;
200 --stop) _koha_plack_instances ; return 0 ;;
201 --restart) _koha_plack_instances ; return 0 ;;
202 --enable) _koha_noplack_instances ; return 0 ;;
203 --disable) _koha_plack_instances ; return 0 ;;
204 --help) COMPREPLY=() ; return 0 ;; # no more completions
205 -h) COMPREPLY=() ; return 0 ;; # no more completions
206 --quiet) # filter the other quiet switches and go on
207 substract="$substract -e -q"; ;;
208 -q) # filter the other quiet switches and go on
209 substract="$substract -e --quiet"; ;;
211 substract="$substract -e ${COMP_WORDS[i]}"
215 if [[ "$substract" != "" ]]; then
216 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
219 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
223 complete -F _koha-plack koha-plack
227 local cur opts substract
230 _get_comp_words_by_ref cur
231 opts="--start --stop --restart --quiet -q --help -h"
233 # Build a list of the already used option switches
234 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
235 if [[ ${COMP_WORDS[i]} == -* ]]; then
236 case ${COMP_WORDS[i]} in
237 --start) _koha_list_cmd ; return 0 ;;
238 --stop) _koha_list_cmd ; return 0 ;;
239 --restart) _koha_list_cmd ; return 0 ;;
240 --help) COMPREPLY=() ; return 0 ;; # no more completions
241 -h) COMPREPLY=() ; return 0 ;; # no more completions
242 --quiet) # filter the other quiet switches and go on
243 substract="$substract -e -q"; ;;
244 -q) # filter the other quiet switches and go on
245 substract="$substract -e --quiet"; ;;
247 substract="$substract -e ${COMP_WORDS[i]}"
251 if [[ "$substract" != "" ]]; then
252 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
255 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
259 complete -F _koha-indexer koha-indexer
263 local cur opts substract
266 _get_comp_words_by_ref cur
267 opts="--start --stop --restart --status --quiet -q --help -h"
269 # Build a list of the already used option switches
270 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
271 if [[ ${COMP_WORDS[i]} == -* ]]; then
272 case ${COMP_WORDS[i]} in
273 --start) _koha_list_cmd ; return 0 ;;
274 --stop) _koha_list_cmd ; return 0 ;;
275 --restart) _koha_list_cmd ; return 0 ;;
276 --status) _koha_list_cmd ; return 0 ;;
277 --help) COMPREPLY=() ; return 0 ;; # no more completions
278 -h) COMPREPLY=() ; return 0 ;; # no more completions
279 --quiet) # filter the other quiet switches and go on
280 substract="$substract -e -q"; ;;
281 -q) # filter the other quiet switches and go on
282 substract="$substract -e --quiet"; ;;
284 substract="$substract -e ${COMP_WORDS[i]}"
288 if [[ "$substract" != "" ]]; then
289 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
292 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
296 complete -F _koha-zebra koha-zebra
300 local cur opts substract
303 _get_comp_words_by_ref cur
304 opts="--start --stop --restart --status --enable --verbose -v --help -h"
306 # Build a list of the already used option switches
307 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
308 if [[ ${COMP_WORDS[i]} == -* ]]; then
309 case ${COMP_WORDS[i]} in
310 --start) _koha_sip_enabled_instances ; return 0 ;;
311 --stop) _koha_sip_enabled_instances ; return 0 ;;
312 --restart) _koha_sip_enabled_instances ; return 0 ;;
313 --status) _koha_sip_enabled_instances ; return 0 ;;
314 --enable) _koha_sip_disabled ; return 0 ;;
315 --help) COMPREPLY=() ; return 0 ;; # no more completions
316 -h) COMPREPLY=() ; return 0 ;; # no more completions
317 --verbose) # filter the other quiet switches and go on
318 substract="$substract -e -q"; ;;
319 -v) # filter the other quiet switches and go on
320 substract="$substract -e --verbose"; ;;
322 substract="$substract -e ${COMP_WORDS[i]}"
326 if [[ "$substract" != "" ]]; then
327 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
330 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
334 complete -F _koha-sip koha-sip
339 # sh-indent-comment: t
340 # indent-tabs-mode: nil
342 # ex: ts=4 sw=4 et filetype=sh