1#compdef quilt
2
3local -a tmp
4local rc
5
6_quilt_applied () {
7  tmp=( ${(f)"$(quilt applied 2>&1)"} )
8  rc=$?
9  if (( rc == 0 )); then
10    _wanted -V 'applied patches' expl 'patch' compadd "${tmp[@]}"
11  else
12    _message "No applied patches"
13  fi
14}
15
16_quilt_series () {
17  _wanted -V 'patches' expl 'patch' compadd ${(f)"$(quilt series)"}
18}
19
20_quilt_unapplied () {
21  tmp=( ${(f)"$(quilt unapplied 2>&1)"} )
22  rc=$?
23  if (( rc == 0 )); then
24    _wanted -V 'unapplied patches' expl 'patch' compadd "${tmp[@]}"
25  else
26    _message "No unapplied patches"
27  fi
28}
29
30_arguments \
31  '--trace[Runs the command in bash trace mode]' \
32  '--quiltrc[Use the specified configuration file]:files:_files' \
33  '--version[Print the version number and exit]' \
34  ':quilt command:(add annotate applied delete diff edit files fold fork graph
35    grep header import mail new next patches pop previous push refresh remove
36    rename revert series setup snapshot top unapplied upgrade)' \
37  '*::subcmd:->subcmd' && return 0
38
39case "$state" in (subcmd)
40  case "$words[1]" in
41      (add)
42        _arguments '-h' \
43          '-P[Patch to add files to]:quilt series:_quilt_series' \
44          '*:files:_files'
45        ;;
46      (annotate)
47        _arguments '-h' \
48          '-P[Stop checking for changes at the specified rather than the topmost patch]:quilt series:_quilt_series' \
49          ':files:_files'
50        ;;
51      (applied)
52        _arguments '-h' \
53          ':quilt series:_quilt_series'
54        ;;
55      (delete)
56        _arguments '-h' \
57          '-n[Delete the next patch after topmost]' \
58          '-r[Remove the deleted patch file from the patches directory as well]' \
59          '--backup[Rename the patch file to patch~ rather than deleting it]' \
60          ':quilt series:_quilt_series'
61        ;;
62      (diff)
63        _arguments '-h' \
64          '-p[Select a patch style]:quilt patch style:(0 1 ab)' \
65          '-u[Create a unified diff]' \
66          '-U[Create a unified diff with num lines of context]:quilt unified diff: ' \
67          '-c[Create a context diff]' \
68          '-C[Create a context diff with num lines of context]:quilt context diff: ' \
69          '--no-timestamps[Do not include file timestamps in patch headers]' \
70          '--no-index[Do not output Index: lines]' \
71          '-z[Write to standard output the changes that have been made relative to the topmost or specified patch]' \
72          '-R[Create a reverse diff]' \
73          '-P[Create a diff for the specified patch]:quilt series:_quilt_series' \
74          '--combine[Create a combined diff for all patches between this patch and the patch specified with -P]:quilt series:_quilt_series' \
75          '--snapshot[Diff against snapshot]' \
76          '--diff=[Use the specified utility for generating the diff]:quilt select diff utility:_command_names -e' \
77          '--color=[Use syntax coloring]:quilt select color:(always auto never)' \
78          '--sort[Sort files by their name]' \
79          '*:files:_files'
80        ;;
81      (edit)
82        _arguments '-h' \
83          '*:files:_files'
84        ;;
85      (files)
86        _arguments '-h' \
87          '-a[List all files in all applied patches]' \
88          '-l[Add patch name to output]' \
89          '-v[Verbose, more user friendly output]' \
90          '--combine[Create a listing for all patches between this patch and the topmost or specified patch]:quilt series:_quilt_series' \
91          ':quilt series:_quilt_series'
92        ;;
93      (fold)
94        _arguments '-h' \
95          '-R[Apply patch in reverse]' \
96          '-q[Quiet operation]' \
97          '-f[Force apply]' \
98          '-p[The number of pathname components to strip]:quilt select strip-level: '
99        ;;
100      (fork)
101        _arguments '-h'
102        ;;
103      (graph)
104        _arguments '-h' \
105          '--all[Generate a graph including all applied patches and their dependencies]' \
106          '--reduce[Eliminate transitive edges from the graph]' \
107          '--lines[Compute dependencies by looking at the lines the patches modify]:quilt select lines: ' \
108          '--edge-labels=files[Label graph edges with the file names that the adjacent patches modify]' \
109          '-T ps[Directly produce a PostScript output file]' \
110          ':quilt series:_quilt_series'
111        ;;
112      (grep)
113        _arguments '-h'
114        ;;
115      (header)
116        _arguments '-h' \
117          '-a[Append the exiting patch header]' \
118          '-r[Replace the exiting patch header]' \
119          '-e[Edit the header in $EDITOR]' \
120          '--strip-diffstat[Strip diffstat output from the header]' \
121          '--strip-trailing-whitespace[Strip trailing whitespace at the end of lines of the header]' \
122          '--backup[Create a backup copy of the old version of a patch as patch~]' \
123          ':quilt series:_quilt_series'
124        ;;
125      (import)
126        _arguments '-h' \
127          '-p[Number of directory levels to strip when applying]:quilt select strip-level: ' \
128          '-R[Apply patch in reverse]' \
129          '-P[Patch filename to use inside quilt]:quilt select patch filename: ' \
130          '-f[Overwrite/update existing patches]' \
131          '-d[When overwriting in existing patch, keep the old (o), all (a), or new (n) patch header]:quilt select patch:(a n o)' \
132          '*:files:_files'
133        ;;
134      (mail)
135        _arguments '-h' \
136          '-m[Text to use as the text in the introduction]:quilt select text: ' \
137          '-M[Like the -m option, but read the introduction from file]:files:_files' \
138          '--prefix[Use an alternate prefix in the bracketed part of the subjects generated]:quilt select prefix: ' \
139          '--mbox[Store all messages in the specified file in mbox format]:files:_files' \
140          '--send[Send the messages directly]' \
141          '--sender[The envelope sender address to use]:quilt select sender: ' \
142          '--from[From header]:quilt select from: ' \
143          '--subject[Subject header]:quilt select subject: ' \
144          '--to[Append a recipient to the To header]:quilt select to: ' \
145          '--cc[Append a recipient to the Cc header]:quilt select cc: ' \
146          '--bcc[Append a recipient to the Bcc header]:quilt select bcc: ' \
147          '--signature[Append the specified signature to messages]:files:_files' \
148          '--reply-to[Add the appropriate headers to reply to the specified message]:quilt select reply-to: ' \
149          '*:quilt series:_quilt_series'
150        ;;
151      (new)
152        _arguments '-h' \
153          '-p[Select a patch style]:quilt patch style:(0 1 ab)'
154        ;;
155      (next)
156        _arguments '-h' \
157          ':quilt series:_quilt_series'
158        ;;
159      (patches)
160        _arguments '-h' \
161          '-v[Verbose, more user friendly output]' \
162          ':files:_files'
163        ;;
164      (pop)
165        _arguments '-h' \
166          '-a[Remove all applied patches]' \
167          '-f[Force remove]' \
168          '-R[Always verify if the patch removes cleanly]' \
169          '-q[Quiet operation]' \
170          '-v[Verbose operation]' \
171          ':quilt applied:_quilt_applied'
172        ;;
173      (previous)
174        _arguments '-h' \
175          ':quilt series:_quilt_series'
176        ;;
177      (push)
178        _arguments '-h' \
179          '-a[Apply all patches in the series file]' \
180          '-q[Quiet operation]' \
181          '-f[Force apply, even if the patch has rejects]' \
182          '-v[Verbose operation]' \
183          '--fuzz[Set the maximum fuzz factor]' \
184          '--merge=[Merge the patch file into the original files]:quilt select merge:(merge diff3)' \
185          '--leave-rejects[Leave around the reject files patch produced]' \
186          '--color=[Use syntax coloring]:quilt select color:(always auto never)' \
187          ':quilt unapplied:_quilt_unapplied'
188        ;;
189      (refresh)
190        _arguments '-h' \
191          '-p[Select a patch style]:quilt patch style:(0 1 ab)' \
192          '-u[Create a unified diff]' \
193          '-U[Create a unified diff with num lines of context]:quilt unified diff: ' \
194          '-c[Create a context diff]' \
195          '-C[Create a context diff with num lines of context]:quilt context diff: ' \
196          '-z[Create a new patch containing the changes instead of refreshing the topmost patch]:quilt select new patch name: ' \
197          '--no-timestamps[Do not include file timestamps in patch headers]' \
198          '--no-index[Do not output Index: lines]' \
199          '--diffstat[Add a diffstat section to the patch header, or replace the existing diffstat section]' \
200          '-f[Enforce refreshing of a patch that is not on top]' \
201          '--backup[Create a backup copy of the old version of a patch as patch~]' \
202          '--sort[Sort files by their name instead of preserving the original order]' \
203          '--strip-trailing-whitespace[Strip trailing whitespace at the end of lines]' \
204          ':quilt series:_quilt_series'
205        ;;
206      (remove)
207        _arguments '-h' \
208          '-P[Patch to remove]:quilt series:_quilt_series'
209        ;;
210      (rename)
211        _arguments '-h' \
212          '-P[Patch to rename]:quilt series:_quilt_series'
213        ;;
214      (revert)
215        _arguments '-h' \
216          '-P[Revert changes in the named patch]:quilt series:_quilt_series' \
217          '*:files:_files'
218        ;;
219      (series)
220        _arguments '-h' \
221          '-v[Verbose, more user friendly output]'
222        ;;
223      (setup)
224        _arguments '-h' \
225          '-d[Optional path prefix for the resulting source tree]:quilt select path-prefix: ' \
226          '--sourcedir[Directory that contains the package sources]:quilt select package sources directory: ' \
227          '-v[Verbose debug output]' \
228          '--fuzz[Set the maximum fuzz factor]' \
229          ':files:_files'
230        ;;
231      (snapshot)
232        _arguments '-h' \
233          '-d[Remove current snapshot]'
234        ;;
235      (top)
236        _arguments '-h'
237        ;;
238      (unapplied)
239        _arguments '-h' \
240          ':quilt series:_quilt_series'
241        ;;
242      (upgrade)
243        _arguments '-h'
244        ;;
245      (*)
246        ;;
247  esac
248  ;;
249esac
250