File: kopano-bash-completion.sh

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (348 lines) | stat: -rwxr-xr-x 8,164 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#-*- mode: shell-script;-*-
# SPDX-License-Identifier: AGPL-3.0-only

# kopano completion (admin, backup, dagent, archiver, fsck, passwd..)

shopt -q extglob
_kopano_old_extglob=$?
shopt -s extglob

_kopano__hosts()
{
	local host_completes
	host_completes='file:///var/run/kopano/server.sock http://localhost:236/ https://localhost:237/'
	COMPREPLY=( $( compgen -W "$host_completes" -- ${COMP_WORDS[COMP_CWORD]} ) )
	return 0
}

_kopano__userlist()
{
	# what todo with maybe passed --host ?
	# what todo with maybe passed -I company, --type ... ?

	local users
	users=$(kopano-admin -l | grep -v ^User | grep -v username | grep -v SYSTEM | grep -v -- -- | awk {'print $1'})
	COMPREPLY=( $( compgen -W "$users" -- ${COMP_WORDS[COMP_CWORD]} ) )
	return 0
}

_kopano__grouplist()
{
	# what todo with maybe passed --host ?
	# what todo with maybe passed -I company, --type ... ?

	local groups
	groups=$(kopano-admin -L | grep -v ^Group | grep -v groupname | grep -v Everyone | grep -v -- -- | awk {'print $1'})
	COMPREPLY=( $( compgen -W "$groups" -- ${COMP_WORDS[COMP_CWORD]} ) )
	return 0
}

_kopano__companylist()
{
	# what todo with maybe passed --host ?

	local users
	users=$(kopano-admin --list-companies | tail -n +4 | awk {'print $1'})
	COMPREPLY=( $( compgen -W "$users" -- ${COMP_WORDS[COMP_CWORD]} ) )
	return 0
}

_kopano_stats_options()
{
	list='--system --session --users --company --top --user -u --host -h'
	COMPREPLY=( $( compgen -W "$list" -- ${COMP_WORDS[COMP_CWORD]} ) )
}
complete -F _kopano_stats_options kopano-stats

_kopano_admin_options()
{
	local cur prev short_actions long_actions possiblelist

	short_actions='-V -l -L -s -c -u -d -U -P -p -f -e -a -h -g -G -b -B -i -I -n'
	long_actions='--create-store --remove-store --hook-store --unhook-store --copyto-public --details --type --help --host --sync --qh --qs --qw --qo --udqh --udqs --udqw --udqo --lang --mr-accept --mr-decline-conflict --mr-decline-recurring --add-sendas --del-sendas --list-sendas --list-orphans --create-company --update-company --delete-company --list-companies --add-to-viewlist --del-from-viewlist --list-view --add-to-adminlist --del-from-adminlist --list-admin --set-system-admin --add-userquota-recipient --del-userquota-recipient --list-userquota-recipient --add-companyquota-recipient --del-companyquota-recipient --list-companyquota-recipient --purge-softdelete --purge-deferred --config --enable-feature --disable-feature --clear-cache --user-count --force-resync --reset-folder-count --node'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(h|-host))
		# host completion is quite senseless, since you need admin rights, and no ssl cert can be used in kopano-admin
		_kopano__hosts
		return 0
		;;

		-@(-qo|-qdqo|-mr-*|a|n))
		possiblelist="yes no"
		;;

		--config)
		_filedir
		return 0
		;;

		-@(-lang|-create-company|c|U|p|f|e|g|-qh|-qs|-qw|-udqh|-udqs|-udqw|-list-admin|-list-userquota-recipient|-list-companyquota-recipient|-purge-softdelete))
		# opt req, no hints
		return 0
		;;

		-@(G|i))
		_kopano__grouplist
		return 0
		;;

		-@(I|-list-view|-add-to-viewlist|-del-from-viewlist))
		_kopano__companylist
		return 0
		;;

		-@(-details|-unhook-store|-create-store|u|d|b|B|-list-sendas|-add-sendas|-del-sendas|-add-to-adminlist|-del-from-adminlist|-set-system-admin|-add-userquota-recipient|-del-userquota-recipient||-add-companyquota-recipient|-del-companyquota-recipient|-force-resync|-reset-folder-count))
		_kopano__userlist
		return 0
		;;

		--type)
		possiblelist="user group company"
		;;
		
		-@(-en|-dis)able-feature)
		possiblelist="imap pop3 mobile outlook webapp"
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi

	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	return 0
}
complete -F _kopano_admin_options $filenames kopano-admin

_kopano_backup_options()
{
	local cur short_actions long_actions possiblelist

	short_actions='-a -p -P -u -h -o -c -s -i -J -N -v'
	long_actions='--all --user --public --company --company-public --store --skip-junk --skip-public --output --host --config --verbose --help'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(h|-host))
		_kopano__hosts
		return 0
		;;

		# actually the (.*).zbk.index part ?
		-@(u|-user|f|-from))
		_kopano__userlist
		;;

		-@(s|-company|P|-company-public))
		_kopano__companylist
		;;

		-@(i|-restorefile|c|-config))
		_filedir
		return 0
		;;

		-@(o|-output))
		_filedir -d
		return 0
		;;

		-@(i|-store))
		# opt req, no hints
		return 0
		;;

		# empty parameters, ok with help and read??
		--@(all|public|skip-junk|skip-public|verbose|help))
		;;
		-@(a|p|J|N|v))
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi
	
	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	return 0
}
complete -F _kopano_backup_options $filenames kopano-backup

_kopano_dagent_options()
{
	local cur short_actions long_actions possiblelist

	short_actions='-c -j -f -d -h -a -F -P -p -q -s -v -e -n -C -V -r -R -l -N'
	long_actions='--help --config --junk --file --host --daemonize --listen --folder --public --create --read --do-not-notify --add-imap-data'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(h|-host))
		_kopano__hosts
		return 0
		;;

		-@(f|-file|c|-config|a))
		_filedir
		return 0
		;;

		-@(P|-public|F|-folder|p))
		# opt req, no hints
		return 0
		;;

		# empty parameters, ok with help and read??
		--@(help|junk|daemonize|listen|read|do-not-notify))
		;;
		-@(j|d|q|s|v|e|n|r|l|R|N))
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi
	
	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	
	return 0
}
complete -F _kopano_dagent_options $filenames kopano-dagent

_kopano_fsck_options()
{
	local cur short_actions long_actions possiblelist

	short_actions='-u -p -P -h -a'
	long_actions='--help --host --pass --user --calendar --contact --task --all --autofix --autodel --checkonly'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(h|-host))
		_kopano__hosts
		return 0
		;;

		-@(u|-user))
		_kopano__userlist
		return 0
		;;

		-@(p|-pass))
		# opt req, no hints
		return 0
		;;

		# empty parameters
		--@(calendar|contact|task|all|autofix|autodel|checkonly))
		;;
		-@(P|a))
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi
	
	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	
	return 0
}
complete -F _kopano_fsck_options kopano-fsck

_kopano_passwd_options()
{
	local cur short_actions long_actions possiblelist

	short_actions='-u -p -h -o -V'
	long_actions='--help --host'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(h|-host))
		_kopano__hosts
		return 0
		;;

		-@(u|a))
		_kopano__userlist
		return 0
		;;

		-@(p|o|V))
		# empty parameters
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi
	
	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	
	return 0
}
complete -F _kopano_passwd_options kopano-passwd

_kopano_archiver_options()
{
	local cur short_actions long_actions possiblelist

	short_actions='-u -l -A -w -c'
	long_actions='--list --archive --local-only --attach-to --detach-from --archive-folder --archive-server --no-folder --write --config --help'

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}

	case "$prev" in
		-@(u|-attach-to|-detach-from))
		_kopano__userlist
		return 0
		;;

		--archive-server)
		_kopano__hosts
		return 0
		;;

		-@(c|-config))
		_filedir
		return 0
		;;

		-@(l|w|-list|-local-only|-archive-folder|-no-folder|-writable|-help))
		# empty parameters
		;;
	esac

	if [ -z "$possiblelist" ]; then
		possiblelist="$short_actions $long_actions"
	fi
	
	COMPREPLY=( $( compgen -W "$possiblelist" -- "$cur" ) )
	
	return 0
}
complete -F _kopano_archiver_options kopano-archiver

if test "$_kopano_old_extglob" != 0; then
	shopt -u extglob
fi