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 | ||
a4c8dd51 GM |
30 | (defgroup pcmpl-rpm nil |
31 | "Options for rpm completion." | |
32 | :group 'pcomplete | |
33 | :prefix "pcmpl-rpm-") | |
34 | ||
35 | ;; rpm -qa can be slow. Adding --nodigest --nosignature is MUCH faster. | |
36 | (defcustom pcmpl-rpm-query-options | |
37 | (let (opts) | |
38 | (with-temp-buffer | |
39 | (when (ignore-errors (call-process "rpm" nil t nil "--help")) | |
40 | (if (search-backward "--nodigest " nil 'move) | |
41 | (setq opts '("--nodigest"))) | |
42 | (goto-char (point-min)) | |
43 | (if (search-forward "--nosignature " nil t) | |
44 | (push "--nosignature" opts)))) | |
45 | opts) | |
46 | "List of extra options to add to an rpm query command." | |
47 | :version "24.2" | |
48 | :type '(repeat string) | |
49 | :group 'pcmpl-rpm) | |
50 | ||
4fa9f636 GM |
51 | ;; Functions: |
52 | ||
a4c8dd51 GM |
53 | ;; TODO |
54 | ;; This can be slow, so: | |
bf6fa423 GM |
55 | ;; Consider caching the result (cf woman). |
56 | ;; Consider printing an explanatory message before running -qa. | |
a4c8dd51 GM |
57 | (defun pcmpl-rpm-packages () |
58 | "Return a list of all installed rpm packages." | |
59 | (split-string (apply 'pcomplete-process-result "rpm" | |
60 | (append '("-q" "-a") pcmpl-rpm-query-options)))) | |
4fa9f636 | 61 | |
a4c8dd51 GM |
62 | ;; Should this use pcmpl-rpm-query-options? |
63 | ;; I don't think it would speed it up at all (?). | |
4fa9f636 GM |
64 | (defun pcmpl-rpm-all-query (flag) |
65 | (message "Querying all packages with `%s'..." flag) | |
66 | (let ((pkgs (pcmpl-rpm-packages)) | |
67 | (provs (list t))) | |
68 | (while pkgs | |
69 | (nconc provs (split-string | |
70 | (pcomplete-process-result | |
71 | "rpm" "-q" (car pkgs) flag))) | |
72 | (setq pkgs (cdr pkgs))) | |
73 | (pcomplete-uniqify-list (cdr provs)))) | |
74 | ||
75 | (defsubst pcmpl-rpm-files () | |
76 | (pcomplete-dirs-or-entries "\\.rpm\\'")) | |
77 | ||
78 | ;;;###autoload | |
79 | (defun pcomplete/rpm () | |
33e2c2e5 GM |
80 | "Completion for the `rpm' command." |
81 | ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system. | |
4fa9f636 GM |
82 | (let (mode) |
83 | (while (<= pcomplete-index pcomplete-last) | |
84 | (unless mode | |
85 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
86 | (pcomplete-here* | |
87 | '("--addsign" | |
88 | "--checksig" | |
89 | "--erase" | |
90 | "--help" | |
91 | "--initdb" | |
92 | "--install" | |
93 | "--pipe" | |
94 | "--querytags" | |
95 | "--rebuild" | |
96 | "--rebuilddb" | |
97 | "--recompile" | |
98 | "--resign" | |
99 | "--rmsource" | |
100 | "--setperms" | |
101 | "--setugids" | |
102 | "--upgrade" | |
103 | "--verify" | |
104 | "--version")) | |
105 | (pcomplete-opt "vqVyiUebtK"))) | |
106 | ; -b<stage> <spec> | |
107 | ; -t<stage> <tarball> - build package, where <stage> is one of: | |
108 | ; p - prep (unpack sources and apply patches) | |
109 | ; l - list check (do some cursory checks on %files) | |
110 | ; c - compile (prep and compile) | |
111 | ; i - install (prep, compile, install) | |
112 | ; b - binary package (prep, compile, install, package) | |
113 | ; a - bin/src package (prep, compile, install, package) | |
114 | (cond | |
115 | ((or (eq mode 'query) | |
116 | (pcomplete-match "-[^-]*q")) | |
117 | (setq mode 'query) | |
118 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
119 | (progn | |
120 | (pcomplete-here* | |
121 | '("--changelog" | |
122 | "--dbpath" | |
123 | "--dump" | |
bf6fa423 | 124 | "--file" |
4fa9f636 GM |
125 | "--ftpport" ;nyi for the next four |
126 | "--ftpproxy" | |
127 | "--httpport" | |
128 | "--httpproxy" | |
129 | "--provides" | |
130 | "--queryformat" | |
131 | "--rcfile" | |
132 | "--requires" | |
133 | "--root" | |
134 | "--scripts" | |
135 | "--triggeredby" | |
136 | "--whatprovides" | |
137 | "--whatrequires")) | |
138 | (cond | |
139 | ((pcomplete-test "--dbpath") | |
140 | (pcomplete-here* (pcomplete-dirs))) | |
141 | ((pcomplete-test "--queryformat") | |
142 | (pcomplete-here*)) | |
143 | ((pcomplete-test "--rcfile") | |
144 | (pcomplete-here* (pcomplete-entries))) | |
bf6fa423 GM |
145 | ((pcomplete-test "--file") |
146 | (pcomplete-here* (pcomplete-entries))) | |
4fa9f636 GM |
147 | ((pcomplete-test "--root") |
148 | (pcomplete-here* (pcomplete-dirs))) | |
149 | ((pcomplete-test "--scripts") | |
150 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
151 | (pcomplete-here* '("--triggers")))) | |
152 | ((pcomplete-test "--triggeredby") | |
153 | (pcomplete-here* (pcmpl-rpm-packages))) | |
154 | ((pcomplete-test "--whatprovides") | |
155 | (pcomplete-here* | |
156 | (pcmpl-rpm-all-query "--provides"))) | |
157 | ((pcomplete-test "--whatrequires") | |
158 | (pcomplete-here* | |
159 | (pcmpl-rpm-all-query "--requires"))))) | |
160 | (if (pcomplete-match "^-" 0) | |
161 | (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR") | |
1258fede | 162 | (if (pcomplete-test "-[^-]*p" 'first 1) |
33e2c2e5 | 163 | (pcomplete-here (pcmpl-rpm-files)) |
bf6fa423 GM |
164 | (if (pcomplete-test "-[^-]*f" 'first 1) |
165 | (pcomplete-here* (pcomplete-entries)) | |
166 | (pcomplete-here (pcmpl-rpm-packages))))))) | |
4fa9f636 GM |
167 | ((pcomplete-test "--pipe") |
168 | (pcomplete-here* (funcall pcomplete-command-completion-function))) | |
169 | ((pcomplete-test "--rmsource") | |
170 | (pcomplete-here* (pcomplete-entries)) | |
171 | (throw 'pcomplete-completions nil)) | |
172 | ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'") | |
173 | (pcomplete-here (pcmpl-rpm-files)) | |
174 | (throw 'pcomplete-completions nil)) | |
175 | ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'") | |
176 | (while (pcomplete-here (pcmpl-rpm-files)))) | |
177 | ((or (eq mode 'checksig) | |
178 | (pcomplete-test "--checksig")) | |
179 | (setq mode 'checksig) | |
180 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
181 | (progn | |
182 | (pcomplete-here* | |
183 | '("--nopgp" | |
184 | "--nogpg" | |
185 | "--nomd5" | |
186 | "--rcfile")) | |
187 | (cond | |
188 | ((pcomplete-test "--rcfile") | |
189 | (pcomplete-here* (pcomplete-entries))))) | |
190 | (if (pcomplete-match "^-" 0) | |
191 | (pcomplete-opt "v") | |
192 | (pcomplete-here (pcmpl-rpm-files))))) | |
193 | ((or (eq mode 'rebuilddb) | |
194 | (pcomplete-test "--rebuilddb")) | |
195 | (setq mode 'rebuilddb) | |
196 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
197 | (progn | |
198 | (pcomplete-here* | |
199 | '("--dbpath" | |
200 | "--root" | |
201 | "--rcfile")) | |
202 | (cond | |
203 | ((pcomplete-test "--dbpath") | |
204 | (pcomplete-here* (pcomplete-dirs))) | |
205 | ((pcomplete-test "--root") | |
206 | (pcomplete-here* (pcomplete-dirs))) | |
207 | ((pcomplete-test "--rcfile") | |
208 | (pcomplete-here* (pcomplete-entries))))) | |
209 | (if (pcomplete-match "^-" 0) | |
210 | (pcomplete-opt "v") | |
211 | (pcomplete-here)))) | |
212 | ((memq mode '(install upgrade)) | |
213 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
214 | (progn | |
215 | (pcomplete-here* | |
216 | (append | |
217 | '("--allfiles" | |
218 | "--badreloc" | |
219 | "--dbpath" | |
220 | "--excludedocs" | |
221 | "--excludepath" | |
222 | "--force" | |
223 | "--hash" | |
224 | "--ignorearch" | |
225 | "--ignoreos" | |
226 | "--ignoresize" | |
227 | "--includedocs" | |
228 | "--justdb" | |
229 | "--nodeps" | |
230 | "--noorder" | |
231 | "--noscripts" | |
232 | "--notriggers") | |
233 | (if (eq mode 'upgrade) | |
234 | '("--oldpackage")) | |
235 | '("--percent" | |
236 | "--prefix" | |
237 | "--rcfile" | |
238 | "--relocate" | |
239 | "--replacefiles" | |
240 | "--replacepkgs" | |
241 | "--root"))) | |
242 | (cond | |
243 | ((pcomplete-test "--dbpath") | |
244 | (pcomplete-here* (pcomplete-dirs))) | |
245 | ((pcomplete-test "--relocate") | |
246 | (pcomplete-here*)) | |
247 | ((pcomplete-test "--rcfile") | |
248 | (pcomplete-here* (pcomplete-entries))) | |
249 | ((pcomplete-test "--excludepath") | |
250 | (pcomplete-here* (pcomplete-entries))) | |
251 | ((pcomplete-test "--root") | |
252 | (pcomplete-here* (pcomplete-dirs))) | |
253 | ((pcomplete-test "--prefix") | |
254 | (pcomplete-here* (pcomplete-dirs))))) | |
255 | (if (pcomplete-match "^-" 0) | |
256 | (pcomplete-opt "vh") | |
257 | (pcomplete-here (pcmpl-rpm-files))))) | |
258 | ((or (pcomplete-test "--install") | |
259 | (pcomplete-match "-[^-]*i")) | |
260 | (setq mode 'install)) | |
261 | ((or (pcomplete-test "--upgrade") | |
262 | (pcomplete-match "-[^-]*U")) | |
263 | (setq mode 'upgrade)) | |
264 | ((or (eq mode 'erase) | |
265 | (pcomplete-test "--erase") | |
266 | (pcomplete-match "-[^-]*e")) | |
267 | (setq mode 'erase) | |
268 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
269 | (progn | |
270 | (pcomplete-here* | |
271 | '("--allmatches" | |
272 | "--dbpath" | |
273 | "--justdb" | |
274 | "--nodeps" | |
275 | "--noorder" | |
276 | "--noscripts" | |
277 | "--notriggers" | |
278 | "--rcfile" | |
279 | "--root")) | |
280 | (cond | |
281 | ((pcomplete-test "--dbpath") | |
282 | (pcomplete-here* (pcomplete-dirs))) | |
283 | ((pcomplete-test "--rcfile") | |
284 | (pcomplete-here* (pcomplete-entries))) | |
285 | ((pcomplete-test "--root") | |
286 | (pcomplete-here* (pcomplete-dirs))))) | |
287 | (if (pcomplete-match "^-" 0) | |
288 | (pcomplete-opt "v") | |
289 | (pcomplete-here (pcmpl-rpm-packages))))) | |
290 | ((or (eq mode 'verify) | |
291 | (pcomplete-test "--verify")) | |
292 | (setq mode 'verify) | |
293 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
294 | (progn | |
295 | (pcomplete-here* | |
296 | '("--dbpath" | |
297 | "--nodeps" | |
298 | "--nofiles" | |
299 | "--nomd5" | |
300 | "--rcfile" | |
301 | "--root" | |
302 | "--triggeredby" | |
303 | "--whatprovides" | |
304 | "--whatrequires")) | |
305 | (cond | |
306 | ((pcomplete-test "--dbpath") | |
307 | (pcomplete-here* (pcomplete-dirs))) | |
308 | ((pcomplete-test "--rcfile") | |
309 | (pcomplete-here* (pcomplete-entries))) | |
310 | ((pcomplete-test "--root") | |
311 | (pcomplete-here* (pcomplete-dirs))) | |
312 | ((pcomplete-test "--triggeredby") | |
313 | (pcomplete-here* (pcmpl-rpm-packages))) | |
314 | ((pcomplete-test "--whatprovides") | |
315 | (pcomplete-here* | |
316 | (pcmpl-rpm-all-query "--provides"))) | |
317 | ((pcomplete-test "--whatrequires") | |
318 | (pcomplete-here* | |
319 | (pcmpl-rpm-all-query "--requires"))))) | |
320 | (if (pcomplete-match "^-" 0) | |
321 | (pcomplete-opt "af.p(pcmpl-rpm-files)v") | |
322 | (pcomplete-here (pcmpl-rpm-packages))))) | |
323 | ((or (memq mode '(build test)) | |
324 | (pcomplete-match "\\`-[bt]")) | |
325 | (setq mode (if (pcomplete-match "\\`-b") | |
326 | 'build | |
327 | 'test)) | |
328 | (if (pcomplete-match "^--\\(.*\\)" 0) | |
329 | (progn | |
330 | (pcomplete-here* | |
331 | '("--buildroot" | |
332 | "--clean" | |
333 | "--nobuild" | |
334 | "--rcfile" | |
335 | "--rmsource" | |
336 | "--short-circuit" | |
337 | "--sign" | |
338 | "--target" | |
339 | "--timecheck")) | |
340 | (cond | |
341 | ((pcomplete-test "--buildroot") | |
342 | (pcomplete-here* (pcomplete-dirs))) | |
343 | ((pcomplete-test "--rcfile") | |
344 | (pcomplete-here* (pcomplete-entries))) | |
345 | ((pcomplete-test "--timecheck") | |
346 | (pcomplete-here*)))) | |
347 | (if (pcomplete-match "^-" 0) | |
348 | (pcomplete-opt "v") | |
349 | (pcomplete-here | |
9ffdd3ba SM |
350 | (pcomplete-dirs-or-entries (if (eq mode 'test) |
351 | "\\.tar\\'" | |
352 | "\\.spec\\'")))))) | |
4fa9f636 | 353 | (t |
60370d40 | 354 | (error "You must select a mode: -q, -i, -U, --verify, etc")))))) |
4fa9f636 | 355 | |
4c814fd2 GM |
356 | (provide 'pcmpl-rpm) |
357 | ||
4fa9f636 | 358 | ;;; pcmpl-rpm.el ends here |