1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 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 RedHat's `rpm' tool.
31 (defgroup pcmpl-rpm nil
32 "Functions for dealing with CVS 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 RedHat's `rpm' command.
57 These rules were taken from the output of `rpm --help' on a RedHat 6.1
58 system. They follow my interpretation of what followed, but since I'm
59 not a major rpm user/builder, please send me any corrections you find.
60 You can use \\[eshell-report-bug] to do so."
62 (while (<= pcomplete-index pcomplete-last
)
64 (if (pcomplete-match "^--\\(.*\\)" 0)
84 (pcomplete-opt "vqVyiUebtK")))
86 ; -t<stage> <tarball> - build package, where <stage> is one of:
87 ; p - prep (unpack sources and apply patches)
88 ; l - list check (do some cursory checks on %files)
89 ; c - compile (prep and compile)
90 ; i - install (prep, compile, install)
91 ; b - binary package (prep, compile, install, package)
92 ; a - bin/src package (prep, compile, install, package)
95 (pcomplete-match "-[^-]*q"))
97 (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 "--root")
124 (pcomplete-here* (pcomplete-dirs)))
125 ((pcomplete-test "--scripts")
126 (if (pcomplete-match "^--\\(.*\\)" 0)
127 (pcomplete-here* '("--triggers"))))
128 ((pcomplete-test "--triggeredby")
129 (pcomplete-here* (pcmpl-rpm-packages)))
130 ((pcomplete-test "--whatprovides")
132 (pcmpl-rpm-all-query "--provides")))
133 ((pcomplete-test "--whatrequires")
135 (pcmpl-rpm-all-query "--requires")))))
136 (if (pcomplete-match "^-" 0)
137 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
138 (pcomplete-here (pcmpl-rpm-packages)))))
139 ((pcomplete-test "--pipe")
140 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
141 ((pcomplete-test "--rmsource")
142 (pcomplete-here* (pcomplete-entries))
143 (throw 'pcomplete-completions nil
))
144 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
145 (pcomplete-here (pcmpl-rpm-files))
146 (throw 'pcomplete-completions nil
))
147 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
148 (while (pcomplete-here (pcmpl-rpm-files))))
149 ((or (eq mode
'checksig
)
150 (pcomplete-test "--checksig"))
151 (setq mode
'checksig
)
152 (if (pcomplete-match "^--\\(.*\\)" 0)
160 ((pcomplete-test "--rcfile")
161 (pcomplete-here* (pcomplete-entries)))))
162 (if (pcomplete-match "^-" 0)
164 (pcomplete-here (pcmpl-rpm-files)))))
165 ((or (eq mode
'rebuilddb
)
166 (pcomplete-test "--rebuilddb"))
167 (setq mode
'rebuilddb
)
168 (if (pcomplete-match "^--\\(.*\\)" 0)
175 ((pcomplete-test "--dbpath")
176 (pcomplete-here* (pcomplete-dirs)))
177 ((pcomplete-test "--root")
178 (pcomplete-here* (pcomplete-dirs)))
179 ((pcomplete-test "--rcfile")
180 (pcomplete-here* (pcomplete-entries)))))
181 (if (pcomplete-match "^-" 0)
184 ((memq mode
'(install upgrade
))
185 (if (pcomplete-match "^--\\(.*\\)" 0)
205 (if (eq mode
'upgrade
)
215 ((pcomplete-test "--dbpath")
216 (pcomplete-here* (pcomplete-dirs)))
217 ((pcomplete-test "--relocate")
219 ((pcomplete-test "--rcfile")
220 (pcomplete-here* (pcomplete-entries)))
221 ((pcomplete-test "--excludepath")
222 (pcomplete-here* (pcomplete-entries)))
223 ((pcomplete-test "--root")
224 (pcomplete-here* (pcomplete-dirs)))
225 ((pcomplete-test "--prefix")
226 (pcomplete-here* (pcomplete-dirs)))))
227 (if (pcomplete-match "^-" 0)
229 (pcomplete-here (pcmpl-rpm-files)))))
230 ((or (pcomplete-test "--install")
231 (pcomplete-match "-[^-]*i"))
232 (setq mode
'install
))
233 ((or (pcomplete-test "--upgrade")
234 (pcomplete-match "-[^-]*U"))
235 (setq mode
'upgrade
))
236 ((or (eq mode
'erase
)
237 (pcomplete-test "--erase")
238 (pcomplete-match "-[^-]*e"))
240 (if (pcomplete-match "^--\\(.*\\)" 0)
253 ((pcomplete-test "--dbpath")
254 (pcomplete-here* (pcomplete-dirs)))
255 ((pcomplete-test "--rcfile")
256 (pcomplete-here* (pcomplete-entries)))
257 ((pcomplete-test "--root")
258 (pcomplete-here* (pcomplete-dirs)))))
259 (if (pcomplete-match "^-" 0)
261 (pcomplete-here (pcmpl-rpm-packages)))))
262 ((or (eq mode
'verify
)
263 (pcomplete-test "--verify"))
265 (if (pcomplete-match "^--\\(.*\\)" 0)
278 ((pcomplete-test "--dbpath")
279 (pcomplete-here* (pcomplete-dirs)))
280 ((pcomplete-test "--rcfile")
281 (pcomplete-here* (pcomplete-entries)))
282 ((pcomplete-test "--root")
283 (pcomplete-here* (pcomplete-dirs)))
284 ((pcomplete-test "--triggeredby")
285 (pcomplete-here* (pcmpl-rpm-packages)))
286 ((pcomplete-test "--whatprovides")
288 (pcmpl-rpm-all-query "--provides")))
289 ((pcomplete-test "--whatrequires")
291 (pcmpl-rpm-all-query "--requires")))))
292 (if (pcomplete-match "^-" 0)
293 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
294 (pcomplete-here (pcmpl-rpm-packages)))))
295 ((or (memq mode
'(build test
))
296 (pcomplete-match "\\`-[bt]"))
297 (setq mode
(if (pcomplete-match "\\`-b")
300 (if (pcomplete-match "^--\\(.*\\)" 0)
313 ((pcomplete-test "--buildroot")
314 (pcomplete-here* (pcomplete-dirs)))
315 ((pcomplete-test "--rcfile")
316 (pcomplete-here* (pcomplete-entries)))
317 ((pcomplete-test "--timecheck")
319 (if (pcomplete-match "^-" 0)
323 (pcomplete-dirs-or-entries "\\.tar\\'")
324 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
326 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
328 ;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
329 ;;; pcmpl-rpm.el ends here