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
$filer )
62 COMPREPLY
=( $
(compgen
-W "$instancelist" -- $cur ) )
67 _koha_list_cmd
"--email"
70 complete
-F _koha_email_disable koha-email-disable
74 _koha_list_cmd
"--noemail"
77 complete
-F _koha_email_enable koha-email-enable
79 _koha_sip_enabled_instances
()
81 _koha_list_cmd
"--sip"
85 # koha-*-sip autocomplete with sip-enabled instances
86 complete
-F _koha_sip_enabled_instances koha-start-sip
87 complete
-F _koha_sip_enabled_instances koha-restart-sip
88 complete
-F _koha_sip_enabled_instances koha-stop-sip
92 _koha_list_cmd
"--nosip"
96 # koha-enable-sip autocompletes with sip-disabled instances
97 complete
-F _koha_sip_disabled koha-enable-sip
99 _koha_disabled_instances
()
101 _koha_list_cmd
"--disabled"
105 _koha_enabled_instances
()
107 _koha_list_cmd
"--enabled"
111 # koha-enable autocompletes with disabled instances
112 complete
-F _koha_disabled_instances koha-enable
114 # koha-disable autocompletes with enabled instances
115 complete
-F _koha_enabled_instances koha-disable
117 # koha-*-zebra autocomplete with enabled instances
118 complete
-F _koha_enabled_instances koha-start-zebra
119 complete
-F _koha_enabled_instances koha-restart-zebra
120 complete
-F _koha_enabled_instances koha-stop-zebra
124 local cur opts substract
127 _get_comp_words_by_ref cur
128 opts
="--enabled --disabled --email --noemail --sip --nosip --help -h"
130 # Build a list of the already used option switches
131 for (( i
=0; i
< ${#COMP_WORDS[@]}-1; i
++ )); do
132 if [[ ${COMP_WORDS[i]} == -* ]]; then
133 case ${COMP_WORDS[i]} in
135 substract
="$substract -e --enabled"; ;;
137 substract
="$substract -e --disabled"; ;;
139 substract
="$substract -e --noemail"; ;;
141 substract
="$substract -e --email"; ;;
143 substract
="$substract -e --nosip"; ;;
145 substract
="$substract -e --sip"; ;;
147 substract
="$substract -e -h"; ;;
149 substract
="$substract -e --help"; ;;
151 substract
="$substract -e ${COMP_WORDS[i]}"
155 if [[ "$substract" != "" ]]; then
156 opts
=$
( echo $opts |
sed -e 's/ /\n/g' |
grep -v -x $substract )
159 COMPREPLY
=( $
(compgen
-W "$opts" -- $cur ) )
163 complete
-F _koha_list koha-list
168 # sh-indent-comment: t
169 # indent-tabs-mode: nil
171 # ex: ts=4 sw=4 et filetype=sh