Bug 14330: Remove unused email_sender from sendbasket/sendshelf
[koha.git] / debian / koha-common.bash-completion
blob934e27949c2923e2248e7989e3fbb8047ba89996
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_list_cmd()
48 local filter=$1
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 )
58 else
59 instancelist=$( koha-list $filer )
62 COMPREPLY=( $(compgen -W "$instancelist" -- $cur ) )
65 _koha_email_disable()
67 _koha_list_cmd "--email"
68 return 0
70 complete -F _koha_email_disable koha-email-disable
72 _koha_email_enable()
74 _koha_list_cmd "--noemail"
75 return 0
77 complete -F _koha_email_enable koha-email-enable
79 _koha_sip_enabled_instances()
81 _koha_list_cmd "--sip"
82 return 0
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
90 _koha_sip_disabled()
92 _koha_list_cmd "--nosip"
93 return 0
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"
102 return 0
105 _koha_enabled_instances()
107 _koha_list_cmd "--enabled"
108 return 0
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
122 _koha_list()
124 local cur opts substract
126 COMPREPLY=()
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
134 --disabled)
135 substract="$substract -e --enabled"; ;;
136 --enabled)
137 substract="$substract -e --disabled"; ;;
138 --email)
139 substract="$substract -e --noemail"; ;;
140 --noemail)
141 substract="$substract -e --email"; ;;
142 --sip)
143 substract="$substract -e --nosip"; ;;
144 --nosip)
145 substract="$substract -e --sip"; ;;
146 --help)
147 substract="$substract -e -h"; ;;
149 substract="$substract -e --help"; ;;
150 esac
151 substract="$substract -e ${COMP_WORDS[i]}"
153 done
155 if [[ "$substract" != "" ]]; then
156 opts=$( echo $opts | sed -e 's/ /\n/g' | grep -v -x $substract )
159 COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
161 return 0
163 complete -F _koha_list koha-list
165 # Local variables:
166 # mode: shell-script
167 # sh-basic-offset: 4
168 # sh-indent-comment: t
169 # indent-tabs-mode: nil
170 # End:
171 # ex: ts=4 sw=4 et filetype=sh