1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; These functions provide completion rules for the `rpm' command.
31 (defgroup pcmpl-rpm nil
32 "Functions for dealing with rpm completions."
37 (defsubst pcmpl-rpm-packages
()
38 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
40 (defun pcmpl-rpm-all-query (flag)
41 (message "Querying all packages with `%s'..." flag
)
42 (let ((pkgs (pcmpl-rpm-packages))
45 (nconc provs
(split-string
46 (pcomplete-process-result
47 "rpm" "-q" (car pkgs
) flag
)))
48 (setq pkgs
(cdr pkgs
)))
49 (pcomplete-uniqify-list (cdr provs
))))
51 (defsubst pcmpl-rpm-files
()
52 (pcomplete-dirs-or-entries "\\.rpm\\'"))
55 (defun pcomplete/rpm
()
56 "Completion for the `rpm' command."
57 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
59 (while (<= pcomplete-index pcomplete-last
)
61 (if (pcomplete-match "^--\\(.*\\)" 0)
81 (pcomplete-opt "vqVyiUebtK")))
83 ; -t<stage> <tarball> - build package, where <stage> is one of:
84 ; p - prep (unpack sources and apply patches)
85 ; l - list check (do some cursory checks on %files)
86 ; c - compile (prep and compile)
87 ; i - install (prep, compile, install)
88 ; b - binary package (prep, compile, install, package)
89 ; a - bin/src package (prep, compile, install, package)
92 (pcomplete-match "-[^-]*q"))
94 (if (pcomplete-match "^--\\(.*\\)" 0)
100 "--ftpport" ;nyi for the next four
114 ((pcomplete-test "--dbpath")
115 (pcomplete-here* (pcomplete-dirs)))
116 ((pcomplete-test "--queryformat")
118 ((pcomplete-test "--rcfile")
119 (pcomplete-here* (pcomplete-entries)))
120 ((pcomplete-test "--root")
121 (pcomplete-here* (pcomplete-dirs)))
122 ((pcomplete-test "--scripts")
123 (if (pcomplete-match "^--\\(.*\\)" 0)
124 (pcomplete-here* '("--triggers"))))
125 ((pcomplete-test "--triggeredby")
126 (pcomplete-here* (pcmpl-rpm-packages)))
127 ((pcomplete-test "--whatprovides")
129 (pcmpl-rpm-all-query "--provides")))
130 ((pcomplete-test "--whatrequires")
132 (pcmpl-rpm-all-query "--requires")))))
133 (if (pcomplete-match "^-" 0)
134 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
135 (if (pcomplete-test "-[^-]*p" 'first
1)
136 (pcomplete-here (pcmpl-rpm-files))
137 (pcomplete-here (pcmpl-rpm-packages))))))
138 ((pcomplete-test "--pipe")
139 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
140 ((pcomplete-test "--rmsource")
141 (pcomplete-here* (pcomplete-entries))
142 (throw 'pcomplete-completions nil
))
143 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
144 (pcomplete-here (pcmpl-rpm-files))
145 (throw 'pcomplete-completions nil
))
146 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
147 (while (pcomplete-here (pcmpl-rpm-files))))
148 ((or (eq mode
'checksig
)
149 (pcomplete-test "--checksig"))
150 (setq mode
'checksig
)
151 (if (pcomplete-match "^--\\(.*\\)" 0)
159 ((pcomplete-test "--rcfile")
160 (pcomplete-here* (pcomplete-entries)))))
161 (if (pcomplete-match "^-" 0)
163 (pcomplete-here (pcmpl-rpm-files)))))
164 ((or (eq mode
'rebuilddb
)
165 (pcomplete-test "--rebuilddb"))
166 (setq mode
'rebuilddb
)
167 (if (pcomplete-match "^--\\(.*\\)" 0)
174 ((pcomplete-test "--dbpath")
175 (pcomplete-here* (pcomplete-dirs)))
176 ((pcomplete-test "--root")
177 (pcomplete-here* (pcomplete-dirs)))
178 ((pcomplete-test "--rcfile")
179 (pcomplete-here* (pcomplete-entries)))))
180 (if (pcomplete-match "^-" 0)
183 ((memq mode
'(install upgrade
))
184 (if (pcomplete-match "^--\\(.*\\)" 0)
204 (if (eq mode
'upgrade
)
214 ((pcomplete-test "--dbpath")
215 (pcomplete-here* (pcomplete-dirs)))
216 ((pcomplete-test "--relocate")
218 ((pcomplete-test "--rcfile")
219 (pcomplete-here* (pcomplete-entries)))
220 ((pcomplete-test "--excludepath")
221 (pcomplete-here* (pcomplete-entries)))
222 ((pcomplete-test "--root")
223 (pcomplete-here* (pcomplete-dirs)))
224 ((pcomplete-test "--prefix")
225 (pcomplete-here* (pcomplete-dirs)))))
226 (if (pcomplete-match "^-" 0)
228 (pcomplete-here (pcmpl-rpm-files)))))
229 ((or (pcomplete-test "--install")
230 (pcomplete-match "-[^-]*i"))
231 (setq mode
'install
))
232 ((or (pcomplete-test "--upgrade")
233 (pcomplete-match "-[^-]*U"))
234 (setq mode
'upgrade
))
235 ((or (eq mode
'erase
)
236 (pcomplete-test "--erase")
237 (pcomplete-match "-[^-]*e"))
239 (if (pcomplete-match "^--\\(.*\\)" 0)
252 ((pcomplete-test "--dbpath")
253 (pcomplete-here* (pcomplete-dirs)))
254 ((pcomplete-test "--rcfile")
255 (pcomplete-here* (pcomplete-entries)))
256 ((pcomplete-test "--root")
257 (pcomplete-here* (pcomplete-dirs)))))
258 (if (pcomplete-match "^-" 0)
260 (pcomplete-here (pcmpl-rpm-packages)))))
261 ((or (eq mode
'verify
)
262 (pcomplete-test "--verify"))
264 (if (pcomplete-match "^--\\(.*\\)" 0)
277 ((pcomplete-test "--dbpath")
278 (pcomplete-here* (pcomplete-dirs)))
279 ((pcomplete-test "--rcfile")
280 (pcomplete-here* (pcomplete-entries)))
281 ((pcomplete-test "--root")
282 (pcomplete-here* (pcomplete-dirs)))
283 ((pcomplete-test "--triggeredby")
284 (pcomplete-here* (pcmpl-rpm-packages)))
285 ((pcomplete-test "--whatprovides")
287 (pcmpl-rpm-all-query "--provides")))
288 ((pcomplete-test "--whatrequires")
290 (pcmpl-rpm-all-query "--requires")))))
291 (if (pcomplete-match "^-" 0)
292 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
293 (pcomplete-here (pcmpl-rpm-packages)))))
294 ((or (memq mode
'(build test
))
295 (pcomplete-match "\\`-[bt]"))
296 (setq mode
(if (pcomplete-match "\\`-b")
299 (if (pcomplete-match "^--\\(.*\\)" 0)
312 ((pcomplete-test "--buildroot")
313 (pcomplete-here* (pcomplete-dirs)))
314 ((pcomplete-test "--rcfile")
315 (pcomplete-here* (pcomplete-entries)))
316 ((pcomplete-test "--timecheck")
318 (if (pcomplete-match "^-" 0)
322 (pcomplete-dirs-or-entries "\\.tar\\'")
323 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
325 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
327 ;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
328 ;;; pcmpl-rpm.el ends here