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-mysql autocompletes with a single instance name
134 complete
-F _koha_single_instance koha-mysql
138 local cur opts substract
141 _get_comp_words_by_ref cur
142 opts
="--enabled --disabled --email --noemail --plack --noplack --sip --nosip --help -h"
144 # Build a list of the already used option switches
145 for (( i
=0; i
< ${#COMP_WORDS[@]}-1; i
++ )); do
146 if [[ ${COMP_WORDS[i]} == -* ]]; then
147 case ${COMP_WORDS[i]} in
149 substract
="$substract -e --enabled"; ;;
151 substract
="$substract -e --disabled"; ;;
153 substract
="$substract -e --noemail"; ;;
155 substract
="$substract -e --email"; ;;
157 substract
="$substract -e --noplack"; ;;
159 substract
="$substract -e --plack"; ;;
161 substract
="$substract -e --nosip"; ;;
163 substract
="$substract -e --sip"; ;;
165 substract
="$substract -e -h"; ;;
167 substract
="$substract -e --help"; ;;
169 substract
="$substract -e ${COMP_WORDS[i]}"
173 if [[ "$substract" != "" ]]; then
174 opts
=$
( echo $opts |
sed -e 's/ /\n/g' |
grep -v -x $substract )
177 COMPREPLY
=( $
(compgen
-W "$opts" -- $cur ) )
181 complete
-F _koha_list koha-list
183 _koha_plack_instances
()
185 _koha_list_cmd
"--plack"
189 _koha_noplack_instances
()
191 _koha_list_cmd
"--noplack"
197 local cur opts substract
200 _get_comp_words_by_ref cur
201 opts
="--start --stop --restart --enable --disable --quiet -q --help -h"
203 # Build a list of the already used option switches
204 for (( i
=0; i
< ${#COMP_WORDS[@]}-1; i
++ )); do
205 if [[ ${COMP_WORDS[i]} == -* ]]; then
206 case ${COMP_WORDS[i]} in
207 --start) _koha_plack_instances
; return 0 ;;
208 --stop) _koha_plack_instances
; return 0 ;;
209 --restart) _koha_plack_instances
; return 0 ;;
210 --enable) _koha_noplack_instances
; return 0 ;;
211 --disable) _koha_plack_instances
; return 0 ;;
212 --help) COMPREPLY
=() ; return 0 ;; # no more completions
213 -h) COMPREPLY
=() ; return 0 ;; # no more completions
214 --quiet) # filter the other quiet switches and go on
215 substract
="$substract -e -q"; ;;
216 -q) # filter the other quiet switches and go on
217 substract
="$substract -e --quiet"; ;;
219 substract
="$substract -e ${COMP_WORDS[i]}"
223 if [[ "$substract" != "" ]]; then
224 opts
=$
( echo $opts |
sed -e 's/ /\n/g' |
grep -v -x $substract )
227 COMPREPLY
=( $
(compgen
-W "$opts" -- $cur ) )
231 complete
-F _koha-plack koha-plack
235 local cur opts substract
238 _get_comp_words_by_ref cur
239 opts
="--start --stop --restart --quiet -q --help -h"
241 # Build a list of the already used option switches
242 for (( i
=0; i
< ${#COMP_WORDS[@]}-1; i
++ )); do
243 if [[ ${COMP_WORDS[i]} == -* ]]; then
244 case ${COMP_WORDS[i]} in
245 --start) _koha_list_cmd
; return 0 ;;
246 --stop) _koha_list_cmd
; return 0 ;;
247 --restart) _koha_list_cmd
; return 0 ;;
248 --help) COMPREPLY
=() ; return 0 ;; # no more completions
249 -h) COMPREPLY
=() ; return 0 ;; # no more completions
250 --quiet) # filter the other quiet switches and go on
251 substract
="$substract -e -q"; ;;
252 -q) # filter the other quiet switches and go on
253 substract
="$substract -e --quiet"; ;;
255 substract
="$substract -e ${COMP_WORDS[i]}"
259 if [[ "$substract" != "" ]]; then
260 opts
=$
( echo $opts |
sed -e 's/ /\n/g' |
grep -v -x $substract )
263 COMPREPLY
=( $
(compgen
-W "$opts" -- $cur ) )
267 complete
-F _koha-indexer koha-indexer
271 local cur opts substract
274 _get_comp_words_by_ref cur
275 opts
="--start --stop --restart --status --quiet -q --help -h"
277 # Build a list of the already used option switches
278 for (( i
=0; i
< ${#COMP_WORDS[@]}-1; i
++ )); do
279 if [[ ${COMP_WORDS[i]} == -* ]]; then
280 case ${COMP_WORDS[i]} in
281 --start) _koha_list_cmd
; return 0 ;;
282 --stop) _koha_list_cmd
; return 0 ;;
283 --restart) _koha_list_cmd
; return 0 ;;
284 --status) _koha_list_cmd
; return 0 ;;
285 --help) COMPREPLY
=() ; return 0 ;; # no more completions
286 -h) COMPREPLY
=() ; return 0 ;; # no more completions
287 --quiet) # filter the other quiet switches and go on
288 substract
="$substract -e -q"; ;;
289 -q) # filter the other quiet switches and go on
290 substract
="$substract -e --quiet"; ;;
292 substract
="$substract -e ${COMP_WORDS[i]}"
296 if [[ "$substract" != "" ]]; then
297 opts
=$
( echo $opts |
sed -e 's/ /\n/g' |
grep -v -x $substract )
300 COMPREPLY
=( $
(compgen
-W "$opts" -- $cur ) )
304 complete
-F _koha-zebra koha-zebra
309 # sh-indent-comment: t
310 # indent-tabs-mode: nil
312 # ex: ts=4 sw=4 et filetype=sh