Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; pcmpl-rpm.el --- functions for dealing with rpm completions |
4fa9f636 | 2 | |
bf6fa423 | 3 | ;; Copyright (C) 1999-2012 Free Software Foundation, Inc. |
4fa9f636 | 4 | |
bd78fa1d CY |
5 | ;; Package: pcomplete |
6 | ||
4fa9f636 GM |
7 | ;; This file is part of GNU Emacs. |
8 | ||
eb3fa2cf | 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
4fa9f636 | 10 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
11 | ;; the Free Software Foundation, either version 3 of the License, or |
12 | ;; (at your option) any later version. | |
4fa9f636 GM |
13 | |
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
4fa9f636 GM |
21 | |
22 | ;;; Commentary: | |
23 | ||
33e2c2e5 | 24 | ;; These functions provide completion rules for the `rpm' command. |
4fa9f636 GM |
25 | |
26 | ;;; Code: | |
27 | ||
4fa9f636 GM |
28 | (require 'pcomplete) |
29 | ||
4fa9f636 GM |
30 | ;; Functions: |
31 | ||
bf6fa423 GM |
32 | ;; FIXME rpm -qa can be slow, so: |
33 | ;; Adding --nodigest --nosignature is MUCH faster. | |
34 | ;; (Probably need to test --help for those options though.) | |
35 | ;; Consider caching the result (cf woman). | |
36 | ;; Consider printing an explanatory message before running -qa. | |
37 | ;; | |
38 | ;; Seems pointless for this to be a defsubst. | |
4fa9f636 GM |
39 | (defsubst pcmpl-rpm-packages () |
40 | (split-string (pcomplete-process-result "rpm" "-q" "-a"))) | |
41 | ||
42 | (defun pcmpl-rpm-all-query (flag) | |
43 | (message "Querying all packages with `%s'..." flag) | |
44 | (let ((pkgs (pcmpl-rpm-packages)) | |
45 | (provs (list t))) | |
46 | (while pkgs | |
47 | (nconc provs (split-string | |
48 | (pcomplete-process-result | |
49 | "rpm" "-q" (car pkgs) flag))) | |
50 | (setq pkgs (cdr pkgs))) | |
51 | (pcomplete-uniqify-list (cdr provs)))) | |
52 | ||
53 | (defsubst pcmpl-rpm-files () | |
54 | (pcomplete-dirs-or-entries "\\.rpm\\'")) | |
55 | ||
56 | ;;;###autoload | |
57 | (defun pcomplete/rpm () | |
33e2c2e5 GM |
58 | "Completion for the `rpm' command." |
59 | ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system. | |
4fa9f636 GM |
60 | (let (mode) |
61 | (while (<= pcomplete-index pcomplete-last) | |
62 | (unless mode | |
63 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
64 | (pcomplete-here* | |
65 | '("--addsign" | |
66 | "--checksig" | |
67 | "--erase" | |
68 | "--help" | |
69 | "--initdb" | |
70 | "--install" | |
71 | "--pipe" | |
72 | "--querytags" | |
73 | "--rebuild" | |
74 | "--rebuilddb" | |
75 | "--recompile" | |
76 | "--resign" | |
77 | "--rmsource" | |
78 | "--setperms" | |
79 | "--setugids" | |
80 | "--upgrade" | |
81 | "--verify" | |
82 | "--version")) | |
83 | (pcomplete-opt "vqVyiUebtK"))) | |
84 | ; -b<stage> <spec> | |
85 | ; -t<stage> <tarball> - build package, where <stage> is one of: | |
86 | ; p - prep (unpack sources and apply patches) | |
87 | ; l - list check (do some cursory checks on %files) | |
88 | ; c - compile (prep and compile) | |
89 | ; i - install (prep, compile, install) | |
90 | ; b - binary package (prep, compile, install, package) | |
91 | ; a - bin/src package (prep, compile, install, package) | |
92 | (cond | |
93 | ((or (eq mode 'query) | |
94 | (pcomplete-match "-[^-]*q")) | |
95 | (setq mode 'query) | |
96 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
97 | (progn | |
98 | (pcomplete-here* | |
99 | '("--changelog" | |
100 | "--dbpath" | |
101 | "--dump" | |
bf6fa423 | 102 | "--file" |
4fa9f636 GM |
103 | "--ftpport" ;nyi for the next four |
104 | "--ftpproxy" | |
105 | "--httpport" | |
106 | "--httpproxy" | |
107 | "--provides" | |
108 | "--queryformat" | |
109 | "--rcfile" | |
110 | "--requires" | |
111 | "--root" | |
112 | "--scripts" | |
113 | "--triggeredby" | |
114 | "--whatprovides" | |
115 | "--whatrequires")) | |
116 | (cond | |
117 | ((pcomplete-test "--dbpath") | |
118 | (pcomplete-here* (pcomplete-dirs))) | |
119 | ((pcomplete-test "--queryformat") | |
120 | (pcomplete-here*)) | |
121 | ((pcomplete-test "--rcfile") | |
122 | (pcomplete-here* (pcomplete-entries))) | |
bf6fa423 GM |
123 | ((pcomplete-test "--file") |
124 | (pcomplete-here* (pcomplete-entries))) | |
4fa9f636 GM |
125 | ((pcomplete-test "--root") |
126 | (pcomplete-here* (pcomplete-dirs))) | |
127 | ((pcomplete-test "--scripts") | |
128 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
129 | (pcomplete-here* '("--triggers")))) | |
130 | ((pcomplete-test "--triggeredby") | |
131 | (pcomplete-here* (pcmpl-rpm-packages))) | |
132 | ((pcomplete-test "--whatprovides") | |
133 | (pcomplete-here* | |
134 | (pcmpl-rpm-all-query "--provides"))) | |
135 | ((pcomplete-test "--whatrequires") | |
136 | (pcomplete-here* | |
137 | (pcmpl-rpm-all-query "--requires"))))) | |
138 | (if (pcomplete-match "^-" 0) | |
139 | (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR") | |
1258fede | 140 | (if (pcomplete-test "-[^-]*p" 'first 1) |
33e2c2e5 | 141 | (pcomplete-here (pcmpl-rpm-files)) |
bf6fa423 GM |
142 | (if (pcomplete-test "-[^-]*f" 'first 1) |
143 | (pcomplete-here* (pcomplete-entries)) | |
144 | (pcomplete-here (pcmpl-rpm-packages))))))) | |
4fa9f636 GM |
145 | ((pcomplete-test "--pipe") |
146 | (pcomplete-here* (funcall pcomplete-command-completion-function))) | |
147 | ((pcomplete-test "--rmsource") | |
148 | (pcomplete-here* (pcomplete-entries)) | |
149 | (throw 'pcomplete-completions nil)) | |
150 | ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'") | |
151 | (pcomplete-here (pcmpl-rpm-files)) | |
152 | (throw 'pcomplete-completions nil)) | |
153 | ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'") | |
154 | (while (pcomplete-here (pcmpl-rpm-files)))) | |
155 | ((or (eq mode 'checksig) | |
156 | (pcomplete-test "--checksig")) | |
157 | (setq mode 'checksig) | |
158 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
159 | (progn | |
160 | (pcomplete-here* | |
161 | '("--nopgp" | |
162 | "--nogpg" | |
163 | "--nomd5" | |
164 | "--rcfile")) | |
165 | (cond | |
166 | ((pcomplete-test "--rcfile") | |
167 | (pcomplete-here* (pcomplete-entries))))) | |
168 | (if (pcomplete-match "^-" 0) | |
169 | (pcomplete-opt "v") | |
170 | (pcomplete-here (pcmpl-rpm-files))))) | |
171 | ((or (eq mode 'rebuilddb) | |
172 | (pcomplete-test "--rebuilddb")) | |
173 | (setq mode 'rebuilddb) | |
174 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
175 | (progn | |
176 | (pcomplete-here* | |
177 | '("--dbpath" | |
178 | "--root" | |
179 | "--rcfile")) | |
180 | (cond | |
181 | ((pcomplete-test "--dbpath") | |
182 | (pcomplete-here* (pcomplete-dirs))) | |
183 | ((pcomplete-test "--root") | |
184 | (pcomplete-here* (pcomplete-dirs))) | |
185 | ((pcomplete-test "--rcfile") | |
186 | (pcomplete-here* (pcomplete-entries))))) | |
187 | (if (pcomplete-match "^-" 0) | |
188 | (pcomplete-opt "v") | |
189 | (pcomplete-here)))) | |
190 | ((memq mode '(install upgrade)) | |
191 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
192 | (progn | |
193 | (pcomplete-here* | |
194 | (append | |
195 | '("--allfiles" | |
196 | "--badreloc" | |
197 | "--dbpath" | |
198 | "--excludedocs" | |
199 | "--excludepath" | |
200 | "--force" | |
201 | "--hash" | |
202 | "--ignorearch" | |
203 | "--ignoreos" | |
204 | "--ignoresize" | |
205 | "--includedocs" | |
206 | "--justdb" | |
207 | "--nodeps" | |
208 | "--noorder" | |
209 | "--noscripts" | |
210 | "--notriggers") | |
211 | (if (eq mode 'upgrade) | |
212 | '("--oldpackage")) | |
213 | '("--percent" | |
214 | "--prefix" | |
215 | "--rcfile" | |
216 | "--relocate" | |
217 | "--replacefiles" | |
218 | "--replacepkgs" | |
219 | "--root"))) | |
220 | (cond | |
221 | ((pcomplete-test "--dbpath") | |
222 | (pcomplete-here* (pcomplete-dirs))) | |
223 | ((pcomplete-test "--relocate") | |
224 | (pcomplete-here*)) | |
225 | ((pcomplete-test "--rcfile") | |
226 | (pcomplete-here* (pcomplete-entries))) | |
227 | ((pcomplete-test "--excludepath") | |
228 | (pcomplete-here* (pcomplete-entries))) | |
229 | ((pcomplete-test "--root") | |
230 | (pcomplete-here* (pcomplete-dirs))) | |
231 | ((pcomplete-test "--prefix") | |
232 | (pcomplete-here* (pcomplete-dirs))))) | |
233 | (if (pcomplete-match "^-" 0) | |
234 | (pcomplete-opt "vh") | |
235 | (pcomplete-here (pcmpl-rpm-files))))) | |
236 | ((or (pcomplete-test "--install") | |
237 | (pcomplete-match "-[^-]*i")) | |
238 | (setq mode 'install)) | |
239 | ((or (pcomplete-test "--upgrade") | |
240 | (pcomplete-match "-[^-]*U")) | |
241 | (setq mode 'upgrade)) | |
242 | ((or (eq mode 'erase) | |
243 | (pcomplete-test "--erase") | |
244 | (pcomplete-match "-[^-]*e")) | |
245 | (setq mode 'erase) | |
246 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
247 | (progn | |
248 | (pcomplete-here* | |
249 | '("--allmatches" | |
250 | "--dbpath" | |
251 | "--justdb" | |
252 | "--nodeps" | |
253 | "--noorder" | |
254 | "--noscripts" | |
255 | "--notriggers" | |
256 | "--rcfile" | |
257 | "--root")) | |
258 | (cond | |
259 | ((pcomplete-test "--dbpath") | |
260 | (pcomplete-here* (pcomplete-dirs))) | |
261 | ((pcomplete-test "--rcfile") | |
262 | (pcomplete-here* (pcomplete-entries))) | |
263 | ((pcomplete-test "--root") | |
264 | (pcomplete-here* (pcomplete-dirs))))) | |
265 | (if (pcomplete-match "^-" 0) | |
266 | (pcomplete-opt "v") | |
267 | (pcomplete-here (pcmpl-rpm-packages))))) | |
268 | ((or (eq mode 'verify) | |
269 | (pcomplete-test "--verify")) | |
270 | (setq mode 'verify) | |
271 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
272 | (progn | |
273 | (pcomplete-here* | |
274 | '("--dbpath" | |
275 | "--nodeps" | |
276 | "--nofiles" | |
277 | "--nomd5" | |
278 | "--rcfile" | |
279 | "--root" | |
280 | "--triggeredby" | |
281 | "--whatprovides" | |
282 | "--whatrequires")) | |
283 | (cond | |
284 | ((pcomplete-test "--dbpath") | |
285 | (pcomplete-here* (pcomplete-dirs))) | |
286 | ((pcomplete-test "--rcfile") | |
287 | (pcomplete-here* (pcomplete-entries))) | |
288 | ((pcomplete-test "--root") | |
289 | (pcomplete-here* (pcomplete-dirs))) | |
290 | ((pcomplete-test "--triggeredby") | |
291 | (pcomplete-here* (pcmpl-rpm-packages))) | |
292 | ((pcomplete-test "--whatprovides") | |
293 | (pcomplete-here* | |
294 | (pcmpl-rpm-all-query "--provides"))) | |
295 | ((pcomplete-test "--whatrequires") | |
296 | (pcomplete-here* | |
297 | (pcmpl-rpm-all-query "--requires"))))) | |
298 | (if (pcomplete-match "^-" 0) | |
299 | (pcomplete-opt "af.p(pcmpl-rpm-files)v") | |
300 | (pcomplete-here (pcmpl-rpm-packages))))) | |
301 | ((or (memq mode '(build test)) | |
302 | (pcomplete-match "\\`-[bt]")) | |
303 | (setq mode (if (pcomplete-match "\\`-b") | |
304 | 'build | |
305 | 'test)) | |
306 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
307 | (progn | |
308 | (pcomplete-here* | |
309 | '("--buildroot" | |
310 | "--clean" | |
311 | "--nobuild" | |
312 | "--rcfile" | |
313 | "--rmsource" | |
314 | "--short-circuit" | |
315 | "--sign" | |
316 | "--target" | |
317 | "--timecheck")) | |
318 | (cond | |
319 | ((pcomplete-test "--buildroot") | |
320 | (pcomplete-here* (pcomplete-dirs))) | |
321 | ((pcomplete-test "--rcfile") | |
322 | (pcomplete-here* (pcomplete-entries))) | |
323 | ((pcomplete-test "--timecheck") | |
324 | (pcomplete-here*)))) | |
325 | (if (pcomplete-match "^-" 0) | |
326 | (pcomplete-opt "v") | |
327 | (pcomplete-here | |
9ffdd3ba SM |
328 | (pcomplete-dirs-or-entries (if (eq mode 'test) |
329 | "\\.tar\\'" | |
330 | "\\.spec\\'")))))) | |
4fa9f636 | 331 | (t |
60370d40 | 332 | (error "You must select a mode: -q, -i, -U, --verify, etc")))))) |
4fa9f636 | 333 | |
4c814fd2 GM |
334 | (provide 'pcmpl-rpm) |
335 | ||
4fa9f636 | 336 | ;;; pcmpl-rpm.el ends here |