Bug 17039: Adding 'cancel' link and 'add new item' button to item edit form
[koha.git] / debian / koha-common.bash-completion
blobcb2f3a47ce61d320456040db916ef8bb229a1ac4
1 #!/bin/bash
3 # koha-common.bash-completion script for koha-* commands
5 # This file is part of Koha.
7 # Copyright 2013 Universidad Nacional de Cordoba
8 # Tomas Cohen Arazi
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
13 # version.
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()
24 local substract
26 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
27 if [[ ${COMP_WORDS[i]} == -* ]]; then
28 substract="$substract -e ${COMP_WORDS[i]}"
30 done
32 echo "$substract"
35 _build_substract_instances()
37 local substract
39 for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
40 substract="$substract -e ${COMP_WORDS[i]}"
41 done
43 echo "$substract"
46 _koha_single_instance()
48 local filter=$1
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 ) )
54 else
55 COMPREPLY=()
58 return 0
61 _koha_list_cmd()
63 local filter=$1
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 )
73 else
74 instancelist=$( koha-list $filter )
77 COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
78 return 0
81 _koha_email_disable()
83 _koha_list_cmd "--email"
84 return 0
86 complete -F _koha_email_disable koha-email-disable
88 _koha_email_enable()
90 _koha_list_cmd "--noemail"
91 return 0
93 complete -F _koha_email_enable koha-email-enable
95 _koha_sip_enabled_instances()
97 _koha_list_cmd "--sip"
98 return 0
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
106 _koha_sip_disabled()
108 _koha_list_cmd "--nosip"
109 return 0
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"
118 return 0
121 _koha_enabled_instances()
123 _koha_list_cmd "--enabled"
124 return 0
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
141 _koha_list()
143 local cur opts substract
145 COMPREPLY=()
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
153 --disabled)
154 substract="$substract -e --enabled"; ;;
155 --enabled)
156 substract="$substract -e --disabled"; ;;
157 --email)
158 substract="$substract -e --noemail"; ;;
159 --noemail)
160 substract="$substract -e --email"; ;;
161 --plack)
162 substract="$substract -e --noplack"; ;;
163 --noplack)
164 substract="$substract -e --plack"; ;;
165 --sip)
166 substract="$substract -e --nosip"; ;;
167 --nosip)
168 substract="$substract -e --sip"; ;;
169 --help)
170 substract="$substract -e -h"; ;;
172 substract="$substract -e --help"; ;;
173 esac
174 substract="$substract -e ${COMP_WORDS[i]}"
176 done
178 if [[ "$substract" != "" ]]; then
179 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
182 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
184 return 0
186 complete -F _koha_list koha-list
188 _koha_plack_instances()
190 _koha_list_cmd "--plack"
191 return 0
194 _koha_noplack_instances()
196 _koha_list_cmd "--noplack"
197 return 0
200 _koha-plack()
202 local cur opts substract
204 COMPREPLY=()
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"; ;;
223 esac
224 substract="$substract -e ${COMP_WORDS[i]}"
226 done
228 if [[ "$substract" != "" ]]; then
229 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
232 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
234 return 0
236 complete -F _koha-plack koha-plack
238 _koha-indexer()
240 local cur opts substract
242 COMPREPLY=()
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"; ;;
259 esac
260 substract="$substract -e ${COMP_WORDS[i]}"
262 done
264 if [[ "$substract" != "" ]]; then
265 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
268 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
270 return 0
272 complete -F _koha-indexer koha-indexer
274 _koha-zebra()
276 local cur opts substract
278 COMPREPLY=()
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"; ;;
296 esac
297 substract="$substract -e ${COMP_WORDS[i]}"
299 done
301 if [[ "$substract" != "" ]]; then
302 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
305 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
307 return 0
309 complete -F _koha-zebra koha-zebra
311 # Local variables:
312 # mode: shell-script
313 # sh-basic-offset: 4
314 # sh-indent-comment: t
315 # indent-tabs-mode: nil
316 # End:
317 # ex: ts=4 sw=4 et filetype=sh