1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; These functions provide completion rules for the `rpm' command.
33 (defsubst pcmpl-rpm-packages
()
34 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
36 (defun pcmpl-rpm-all-query (flag)
37 (message "Querying all packages with `%s'..." flag
)
38 (let ((pkgs (pcmpl-rpm-packages))
41 (nconc provs
(split-string
42 (pcomplete-process-result
43 "rpm" "-q" (car pkgs
) flag
)))
44 (setq pkgs
(cdr pkgs
)))
45 (pcomplete-uniqify-list (cdr provs
))))
47 (defsubst pcmpl-rpm-files
()
48 (pcomplete-dirs-or-entries "\\.rpm\\'"))
51 (defun pcomplete/rpm
()
52 "Completion for the `rpm' command."
53 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
55 (while (<= pcomplete-index pcomplete-last
)
57 (if (pcomplete-match "^--\\(.*\\)" 0)
77 (pcomplete-opt "vqVyiUebtK")))
79 ; -t<stage> <tarball> - build package, where <stage> is one of:
80 ; p - prep (unpack sources and apply patches)
81 ; l - list check (do some cursory checks on %files)
82 ; c - compile (prep and compile)
83 ; i - install (prep, compile, install)
84 ; b - binary package (prep, compile, install, package)
85 ; a - bin/src package (prep, compile, install, package)
88 (pcomplete-match "-[^-]*q"))
90 (if (pcomplete-match "^--\\(.*\\)" 0)
96 "--ftpport" ;nyi for the next four
110 ((pcomplete-test "--dbpath")
111 (pcomplete-here* (pcomplete-dirs)))
112 ((pcomplete-test "--queryformat")
114 ((pcomplete-test "--rcfile")
115 (pcomplete-here* (pcomplete-entries)))
116 ((pcomplete-test "--root")
117 (pcomplete-here* (pcomplete-dirs)))
118 ((pcomplete-test "--scripts")
119 (if (pcomplete-match "^--\\(.*\\)" 0)
120 (pcomplete-here* '("--triggers"))))
121 ((pcomplete-test "--triggeredby")
122 (pcomplete-here* (pcmpl-rpm-packages)))
123 ((pcomplete-test "--whatprovides")
125 (pcmpl-rpm-all-query "--provides")))
126 ((pcomplete-test "--whatrequires")
128 (pcmpl-rpm-all-query "--requires")))))
129 (if (pcomplete-match "^-" 0)
130 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
131 (if (pcomplete-test "-[^-]*p" 'first
1)
132 (pcomplete-here (pcmpl-rpm-files))
133 (pcomplete-here (pcmpl-rpm-packages))))))
134 ((pcomplete-test "--pipe")
135 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
136 ((pcomplete-test "--rmsource")
137 (pcomplete-here* (pcomplete-entries))
138 (throw 'pcomplete-completions nil
))
139 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
140 (pcomplete-here (pcmpl-rpm-files))
141 (throw 'pcomplete-completions nil
))
142 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
143 (while (pcomplete-here (pcmpl-rpm-files))))
144 ((or (eq mode
'checksig
)
145 (pcomplete-test "--checksig"))
146 (setq mode
'checksig
)
147 (if (pcomplete-match "^--\\(.*\\)" 0)
155 ((pcomplete-test "--rcfile")
156 (pcomplete-here* (pcomplete-entries)))))
157 (if (pcomplete-match "^-" 0)
159 (pcomplete-here (pcmpl-rpm-files)))))
160 ((or (eq mode
'rebuilddb
)
161 (pcomplete-test "--rebuilddb"))
162 (setq mode
'rebuilddb
)
163 (if (pcomplete-match "^--\\(.*\\)" 0)
170 ((pcomplete-test "--dbpath")
171 (pcomplete-here* (pcomplete-dirs)))
172 ((pcomplete-test "--root")
173 (pcomplete-here* (pcomplete-dirs)))
174 ((pcomplete-test "--rcfile")
175 (pcomplete-here* (pcomplete-entries)))))
176 (if (pcomplete-match "^-" 0)
179 ((memq mode
'(install upgrade
))
180 (if (pcomplete-match "^--\\(.*\\)" 0)
200 (if (eq mode
'upgrade
)
210 ((pcomplete-test "--dbpath")
211 (pcomplete-here* (pcomplete-dirs)))
212 ((pcomplete-test "--relocate")
214 ((pcomplete-test "--rcfile")
215 (pcomplete-here* (pcomplete-entries)))
216 ((pcomplete-test "--excludepath")
217 (pcomplete-here* (pcomplete-entries)))
218 ((pcomplete-test "--root")
219 (pcomplete-here* (pcomplete-dirs)))
220 ((pcomplete-test "--prefix")
221 (pcomplete-here* (pcomplete-dirs)))))
222 (if (pcomplete-match "^-" 0)
224 (pcomplete-here (pcmpl-rpm-files)))))
225 ((or (pcomplete-test "--install")
226 (pcomplete-match "-[^-]*i"))
227 (setq mode
'install
))
228 ((or (pcomplete-test "--upgrade")
229 (pcomplete-match "-[^-]*U"))
230 (setq mode
'upgrade
))
231 ((or (eq mode
'erase
)
232 (pcomplete-test "--erase")
233 (pcomplete-match "-[^-]*e"))
235 (if (pcomplete-match "^--\\(.*\\)" 0)
248 ((pcomplete-test "--dbpath")
249 (pcomplete-here* (pcomplete-dirs)))
250 ((pcomplete-test "--rcfile")
251 (pcomplete-here* (pcomplete-entries)))
252 ((pcomplete-test "--root")
253 (pcomplete-here* (pcomplete-dirs)))))
254 (if (pcomplete-match "^-" 0)
256 (pcomplete-here (pcmpl-rpm-packages)))))
257 ((or (eq mode
'verify
)
258 (pcomplete-test "--verify"))
260 (if (pcomplete-match "^--\\(.*\\)" 0)
273 ((pcomplete-test "--dbpath")
274 (pcomplete-here* (pcomplete-dirs)))
275 ((pcomplete-test "--rcfile")
276 (pcomplete-here* (pcomplete-entries)))
277 ((pcomplete-test "--root")
278 (pcomplete-here* (pcomplete-dirs)))
279 ((pcomplete-test "--triggeredby")
280 (pcomplete-here* (pcmpl-rpm-packages)))
281 ((pcomplete-test "--whatprovides")
283 (pcmpl-rpm-all-query "--provides")))
284 ((pcomplete-test "--whatrequires")
286 (pcmpl-rpm-all-query "--requires")))))
287 (if (pcomplete-match "^-" 0)
288 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
289 (pcomplete-here (pcmpl-rpm-packages)))))
290 ((or (memq mode
'(build test
))
291 (pcomplete-match "\\`-[bt]"))
292 (setq mode
(if (pcomplete-match "\\`-b")
295 (if (pcomplete-match "^--\\(.*\\)" 0)
308 ((pcomplete-test "--buildroot")
309 (pcomplete-here* (pcomplete-dirs)))
310 ((pcomplete-test "--rcfile")
311 (pcomplete-here* (pcomplete-entries)))
312 ((pcomplete-test "--timecheck")
314 (if (pcomplete-match "^-" 0)
318 (pcomplete-dirs-or-entries "\\.tar\\'")
319 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
321 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
325 ;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
326 ;;; pcmpl-rpm.el ends here