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, or (at your option)
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; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; These functions provide completion rules for RedHat's `rpm' tool.
33 (defgroup pcmpl-rpm nil
34 "Functions for dealing with CVS completions."
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 RedHat's `rpm' command.
59 These rules were taken from the output of `rpm --help' on a RedHat 6.1
60 system. They follow my interpretation of what followed, but since I'm
61 not a major rpm user/builder, please send me any corrections you find.
62 You can use \\[eshell-report-bug] to do so."
64 (while (<= pcomplete-index pcomplete-last
)
66 (if (pcomplete-match "^--\\(.*\\)" 0)
86 (pcomplete-opt "vqVyiUebtK")))
88 ; -t<stage> <tarball> - build package, where <stage> is one of:
89 ; p - prep (unpack sources and apply patches)
90 ; l - list check (do some cursory checks on %files)
91 ; c - compile (prep and compile)
92 ; i - install (prep, compile, install)
93 ; b - binary package (prep, compile, install, package)
94 ; a - bin/src package (prep, compile, install, package)
97 (pcomplete-match "-[^-]*q"))
99 (if (pcomplete-match "^--\\(.*\\)" 0)
105 "--ftpport" ;nyi for the next four
119 ((pcomplete-test "--dbpath")
120 (pcomplete-here* (pcomplete-dirs)))
121 ((pcomplete-test "--queryformat")
123 ((pcomplete-test "--rcfile")
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 (pcomplete-here (pcmpl-rpm-packages)))))
141 ((pcomplete-test "--pipe")
142 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
143 ((pcomplete-test "--rmsource")
144 (pcomplete-here* (pcomplete-entries))
145 (throw 'pcomplete-completions nil
))
146 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
147 (pcomplete-here (pcmpl-rpm-files))
148 (throw 'pcomplete-completions nil
))
149 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
150 (while (pcomplete-here (pcmpl-rpm-files))))
151 ((or (eq mode
'checksig
)
152 (pcomplete-test "--checksig"))
153 (setq mode
'checksig
)
154 (if (pcomplete-match "^--\\(.*\\)" 0)
162 ((pcomplete-test "--rcfile")
163 (pcomplete-here* (pcomplete-entries)))))
164 (if (pcomplete-match "^-" 0)
166 (pcomplete-here (pcmpl-rpm-files)))))
167 ((or (eq mode
'rebuilddb
)
168 (pcomplete-test "--rebuilddb"))
169 (setq mode
'rebuilddb
)
170 (if (pcomplete-match "^--\\(.*\\)" 0)
177 ((pcomplete-test "--dbpath")
178 (pcomplete-here* (pcomplete-dirs)))
179 ((pcomplete-test "--root")
180 (pcomplete-here* (pcomplete-dirs)))
181 ((pcomplete-test "--rcfile")
182 (pcomplete-here* (pcomplete-entries)))))
183 (if (pcomplete-match "^-" 0)
186 ((memq mode
'(install upgrade
))
187 (if (pcomplete-match "^--\\(.*\\)" 0)
207 (if (eq mode
'upgrade
)
217 ((pcomplete-test "--dbpath")
218 (pcomplete-here* (pcomplete-dirs)))
219 ((pcomplete-test "--relocate")
221 ((pcomplete-test "--rcfile")
222 (pcomplete-here* (pcomplete-entries)))
223 ((pcomplete-test "--excludepath")
224 (pcomplete-here* (pcomplete-entries)))
225 ((pcomplete-test "--root")
226 (pcomplete-here* (pcomplete-dirs)))
227 ((pcomplete-test "--prefix")
228 (pcomplete-here* (pcomplete-dirs)))))
229 (if (pcomplete-match "^-" 0)
231 (pcomplete-here (pcmpl-rpm-files)))))
232 ((or (pcomplete-test "--install")
233 (pcomplete-match "-[^-]*i"))
234 (setq mode
'install
))
235 ((or (pcomplete-test "--upgrade")
236 (pcomplete-match "-[^-]*U"))
237 (setq mode
'upgrade
))
238 ((or (eq mode
'erase
)
239 (pcomplete-test "--erase")
240 (pcomplete-match "-[^-]*e"))
242 (if (pcomplete-match "^--\\(.*\\)" 0)
255 ((pcomplete-test "--dbpath")
256 (pcomplete-here* (pcomplete-dirs)))
257 ((pcomplete-test "--rcfile")
258 (pcomplete-here* (pcomplete-entries)))
259 ((pcomplete-test "--root")
260 (pcomplete-here* (pcomplete-dirs)))))
261 (if (pcomplete-match "^-" 0)
263 (pcomplete-here (pcmpl-rpm-packages)))))
264 ((or (eq mode
'verify
)
265 (pcomplete-test "--verify"))
267 (if (pcomplete-match "^--\\(.*\\)" 0)
280 ((pcomplete-test "--dbpath")
281 (pcomplete-here* (pcomplete-dirs)))
282 ((pcomplete-test "--rcfile")
283 (pcomplete-here* (pcomplete-entries)))
284 ((pcomplete-test "--root")
285 (pcomplete-here* (pcomplete-dirs)))
286 ((pcomplete-test "--triggeredby")
287 (pcomplete-here* (pcmpl-rpm-packages)))
288 ((pcomplete-test "--whatprovides")
290 (pcmpl-rpm-all-query "--provides")))
291 ((pcomplete-test "--whatrequires")
293 (pcmpl-rpm-all-query "--requires")))))
294 (if (pcomplete-match "^-" 0)
295 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
296 (pcomplete-here (pcmpl-rpm-packages)))))
297 ((or (memq mode
'(build test
))
298 (pcomplete-match "\\`-[bt]"))
299 (setq mode
(if (pcomplete-match "\\`-b")
302 (if (pcomplete-match "^--\\(.*\\)" 0)
315 ((pcomplete-test "--buildroot")
316 (pcomplete-here* (pcomplete-dirs)))
317 ((pcomplete-test "--rcfile")
318 (pcomplete-here* (pcomplete-entries)))
319 ((pcomplete-test "--timecheck")
321 (if (pcomplete-match "^-" 0)
325 (pcomplete-dirs-or-entries "\\.tar\\'")
326 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
328 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
330 ;;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
331 ;;; pcmpl-rpm.el ends here