1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
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.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; These functions provide completion rules for the `rpm' command.
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.
38 ;; Seems pointless for this to be a defsubst.
39 (defsubst pcmpl-rpm-packages
()
40 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
42 (defun pcmpl-rpm-all-query (flag)
43 (message "Querying all packages with `%s'..." flag
)
44 (let ((pkgs (pcmpl-rpm-packages))
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
))))
53 (defsubst pcmpl-rpm-files
()
54 (pcomplete-dirs-or-entries "\\.rpm\\'"))
57 (defun pcomplete/rpm
()
58 "Completion for the `rpm' command."
59 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
61 (while (<= pcomplete-index pcomplete-last
)
63 (if (pcomplete-match "^--\\(.*\\)" 0)
83 (pcomplete-opt "vqVyiUebtK")))
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)
94 (pcomplete-match "-[^-]*q"))
96 (if (pcomplete-match "^--\\(.*\\)" 0)
103 "--ftpport" ;nyi for the next four
117 ((pcomplete-test "--dbpath")
118 (pcomplete-here* (pcomplete-dirs)))
119 ((pcomplete-test "--queryformat")
121 ((pcomplete-test "--rcfile")
122 (pcomplete-here* (pcomplete-entries)))
123 ((pcomplete-test "--file")
124 (pcomplete-here* (pcomplete-entries)))
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")
134 (pcmpl-rpm-all-query "--provides")))
135 ((pcomplete-test "--whatrequires")
137 (pcmpl-rpm-all-query "--requires")))))
138 (if (pcomplete-match "^-" 0)
139 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
140 (if (pcomplete-test "-[^-]*p" 'first
1)
141 (pcomplete-here (pcmpl-rpm-files))
142 (if (pcomplete-test "-[^-]*f" 'first
1)
143 (pcomplete-here* (pcomplete-entries))
144 (pcomplete-here (pcmpl-rpm-packages)))))))
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)
166 ((pcomplete-test "--rcfile")
167 (pcomplete-here* (pcomplete-entries)))))
168 (if (pcomplete-match "^-" 0)
170 (pcomplete-here (pcmpl-rpm-files)))))
171 ((or (eq mode
'rebuilddb
)
172 (pcomplete-test "--rebuilddb"))
173 (setq mode
'rebuilddb
)
174 (if (pcomplete-match "^--\\(.*\\)" 0)
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)
190 ((memq mode
'(install upgrade
))
191 (if (pcomplete-match "^--\\(.*\\)" 0)
211 (if (eq mode
'upgrade
)
221 ((pcomplete-test "--dbpath")
222 (pcomplete-here* (pcomplete-dirs)))
223 ((pcomplete-test "--relocate")
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)
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"))
246 (if (pcomplete-match "^--\\(.*\\)" 0)
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)
267 (pcomplete-here (pcmpl-rpm-packages)))))
268 ((or (eq mode
'verify
)
269 (pcomplete-test "--verify"))
271 (if (pcomplete-match "^--\\(.*\\)" 0)
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")
294 (pcmpl-rpm-all-query "--provides")))
295 ((pcomplete-test "--whatrequires")
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")
306 (if (pcomplete-match "^--\\(.*\\)" 0)
319 ((pcomplete-test "--buildroot")
320 (pcomplete-here* (pcomplete-dirs)))
321 ((pcomplete-test "--rcfile")
322 (pcomplete-here* (pcomplete-entries)))
323 ((pcomplete-test "--timecheck")
325 (if (pcomplete-match "^-" 0)
328 (pcomplete-dirs-or-entries (if (eq mode
'test
)
332 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
336 ;;; pcmpl-rpm.el ends here