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]}"
50 local cur substract instancelist
51 _get_comp_words_by_ref cur
53 # Build a list of the already used words
54 substract=`_build_substract_instances`
56 if [[ "$substract" != "" ]]; then
57 instancelist=$( koha-list $filter | grep -v -x $substract )
59 instancelist=$( koha-list $filter )
62 COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
68 _koha_list_cmd "--email"
71 complete -F _koha_email_disable koha-email-disable
75 _koha_list_cmd "--noemail"
78 complete -F _koha_email_enable koha-email-enable
80 _koha_sip_enabled_instances()
82 _koha_list_cmd "--sip"
86 # koha-*-sip autocomplete with sip-enabled instances
87 complete -F _koha_sip_enabled_instances koha-start-sip
88 complete -F _koha_sip_enabled_instances koha-restart-sip
89 complete -F _koha_sip_enabled_instances koha-stop-sip
93 _koha_list_cmd "--nosip"
97 # koha-enable-sip autocompletes with sip-disabled instances
98 complete -F _koha_sip_disabled koha-enable-sip
100 _koha_disabled_instances()
102 _koha_list_cmd "--disabled"
106 _koha_enabled_instances()
108 _koha_list_cmd "--enabled"
112 # koha-enable autocompletes with disabled instances
113 complete -F _koha_disabled_instances koha-enable
115 # koha-disable autocompletes with enabled instances
116 complete -F _koha_enabled_instances koha-disable
118 # koha-*-zebra autocomplete with enabled instances
119 complete -F _koha_enabled_instances koha-start-zebra
120 complete -F _koha_enabled_instances koha-restart-zebra
121 complete -F _koha_enabled_instances koha-stop-zebra
125 local cur opts substract
128 _get_comp_words_by_ref cur
129 opts="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h"
131 # Build a list of the already used option switches
132 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
133 if [[ ${COMP_WORDS[i]} == -* ]]; then
134 case ${COMP_WORDS[i]} in
136 substract="$substract -e --enabled"; ;;
138 substract="$substract -e --disabled"; ;;
140 substract="$substract -e --noemail"; ;;
142 substract="$substract -e --email"; ;;
144 substract="$substract -e --noplack"; ;;
146 substract="$substract -e --plack"; ;;
148 substract="$substract -e --nosip"; ;;
150 substract="$substract -e --sip"; ;;
152 substract="$substract -e -h"; ;;
154 substract="$substract -e --help"; ;;
156 substract="$substract -e ${COMP_WORDS[i]}"
160 if [[ "$substract" != "" ]]; then
161 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
164 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
168 complete -F _koha_list koha-list
170 _koha_plack_instances()
172 _koha_list_cmd "--plack"
176 _koha_noplack_instances()
178 _koha_list_cmd "--noplack"
184 local cur opts substract
187 _get_comp_words_by_ref cur
188 opts="--start --stop --restart --enable --disable --quiet -q --help -h"
190 # Build a list of the already used option switches
191 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
192 if [[ ${COMP_WORDS[i]} == -* ]]; then
193 case ${COMP_WORDS[i]} in
194 --start) _koha_plack_instances ; return 0 ;;
195 --stop) _koha_plack_instances ; return 0 ;;
196 --restart) _koha_plack_instances ; return 0 ;;
197 --enable) _koha_noplack_instances ; return 0 ;;
198 --disable) _koha_plack_instances ; return 0 ;;
199 --help) COMPREPLY=() ; return 0 ;; # no more completions
200 -h) COMPREPLY=() ; return 0 ;; # no more completions
201 --quiet) # filter the other quiet switches and go on
202 substract="$substract -e '--quiet' -e '-q'"; ;;
203 -q) # filter the other quiet switches and go on
204 substract="$substract -e '--quiet' -e '-q'"; ;;
206 substract="$substract -e ${COMP_WORDS[i]}"
210 if [[ "$substract" != "" ]]; then
211 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
214 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
218 complete -F _koha-plack koha-plack
223 # sh-indent-comment: t
224 # indent-tabs-mode: nil
226 # ex: ts=4 sw=4 et filetype=sh