1#compdef twidge
2## completion for twidge 1.0.8, based on twidge(1)
3
4function _twidge_command {
5	typeset -a twidge_commands
6	typeset -i skip=1
7
8	twidge lscommands | while read cmd desc; do
9		if [[ $cmd == ---* ]] {
10			skip=0
11			continue
12		}
13		if (( skip )) {
14			continue
15		}
16		twidge_commands+="${cmd}:${desc}"
17	done
18
19	_describe command twidge_commands
20}
21
22function _twidge_args {
23	typeset -a args_common args_more args_other args_update
24
25	args_common=(
26		'(-a --all)'{-a,--all}'[receive all content]'
27		'(-e --exec)'{-e,--exec}'[execute command for each retrieved item]:command'
28		'(-l --long)'{-l,--long}'[long output format]'
29		'(-m --mailto)'{-m,--mailto}'[mail retrieved items]:mail address'
30	)
31
32	args_more=(
33		'(-s --saveid)'{-s,--saveid}'[save ID of most recent message]'
34		'(-u --unseen)'{-u,--unseen}'[only show unseen messages]'
35	)
36
37	args_other=(
38		'(-U --username)'{-U,--username}'[show updates of different user]:username'
39	)
40
41	args_update=(
42		'(-i --inreplyto)'{-i,--inreplyto}'[update in reply to a message]:message id'
43		'(-i --inreplyto 1)-r[read RFC2822 Mail]'
44		':status'
45	)
46
47	case ${words[1]} in
48		lsarchive)
49			_arguments $args_common $args_more $args_other
50			;;
51		ls(dm(|archive)|recent|replies|rt(|archive|replies)))
52			_arguments $args_common $args_more
53			;;
54		lsfollow(ers|ing))
55			_arguments $args_common :username
56			;;
57		dmsend)
58			_arguments :recipient :status
59			;;
60		(un|)follow)
61			_message username
62			;;
63		update)
64			_arguments $args_update
65			;;
66	esac
67}
68
69function _twidge {
70	_arguments \
71	'(-c --config)'{-c,--config}'[config file]:file:_files' \
72	'(-d --debug)'{-d,--debug}'[enable debugging output]' \
73	'(-): :_twidge_command' \
74	'(-)*:: :_twidge_args'
75}
76
77_twidge "$@"
78