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 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 (defsubst pcmpl-rpm-packages
()
32 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
34 (defun pcmpl-rpm-all-query (flag)
35 (message "Querying all packages with `%s'..." flag
)
36 (let ((pkgs (pcmpl-rpm-packages))
39 (nconc provs
(split-string
40 (pcomplete-process-result
41 "rpm" "-q" (car pkgs
) flag
)))
42 (setq pkgs
(cdr pkgs
)))
43 (pcomplete-uniqify-list (cdr provs
))))
45 (defsubst pcmpl-rpm-files
()
46 (pcomplete-dirs-or-entries "\\.rpm\\'"))
49 (defun pcomplete/rpm
()
50 "Completion for the `rpm' command."
51 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
53 (while (<= pcomplete-index pcomplete-last
)
55 (if (pcomplete-match "^--\\(.*\\)" 0)
75 (pcomplete-opt "vqVyiUebtK")))
77 ; -t<stage> <tarball> - build package, where <stage> is one of:
78 ; p - prep (unpack sources and apply patches)
79 ; l - list check (do some cursory checks on %files)
80 ; c - compile (prep and compile)
81 ; i - install (prep, compile, install)
82 ; b - binary package (prep, compile, install, package)
83 ; a - bin/src package (prep, compile, install, package)
86 (pcomplete-match "-[^-]*q"))
88 (if (pcomplete-match "^--\\(.*\\)" 0)
94 "--ftpport" ;nyi for the next four
108 ((pcomplete-test "--dbpath")
109 (pcomplete-here* (pcomplete-dirs)))
110 ((pcomplete-test "--queryformat")
112 ((pcomplete-test "--rcfile")
113 (pcomplete-here* (pcomplete-entries)))
114 ((pcomplete-test "--root")
115 (pcomplete-here* (pcomplete-dirs)))
116 ((pcomplete-test "--scripts")
117 (if (pcomplete-match "^--\\(.*\\)" 0)
118 (pcomplete-here* '("--triggers"))))
119 ((pcomplete-test "--triggeredby")
120 (pcomplete-here* (pcmpl-rpm-packages)))
121 ((pcomplete-test "--whatprovides")
123 (pcmpl-rpm-all-query "--provides")))
124 ((pcomplete-test "--whatrequires")
126 (pcmpl-rpm-all-query "--requires")))))
127 (if (pcomplete-match "^-" 0)
128 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
129 (if (pcomplete-test "-[^-]*p" 'first
1)
130 (pcomplete-here (pcmpl-rpm-files))
131 (pcomplete-here (pcmpl-rpm-packages))))))
132 ((pcomplete-test "--pipe")
133 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
134 ((pcomplete-test "--rmsource")
135 (pcomplete-here* (pcomplete-entries))
136 (throw 'pcomplete-completions nil
))
137 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
138 (pcomplete-here (pcmpl-rpm-files))
139 (throw 'pcomplete-completions nil
))
140 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
141 (while (pcomplete-here (pcmpl-rpm-files))))
142 ((or (eq mode
'checksig
)
143 (pcomplete-test "--checksig"))
144 (setq mode
'checksig
)
145 (if (pcomplete-match "^--\\(.*\\)" 0)
153 ((pcomplete-test "--rcfile")
154 (pcomplete-here* (pcomplete-entries)))))
155 (if (pcomplete-match "^-" 0)
157 (pcomplete-here (pcmpl-rpm-files)))))
158 ((or (eq mode
'rebuilddb
)
159 (pcomplete-test "--rebuilddb"))
160 (setq mode
'rebuilddb
)
161 (if (pcomplete-match "^--\\(.*\\)" 0)
168 ((pcomplete-test "--dbpath")
169 (pcomplete-here* (pcomplete-dirs)))
170 ((pcomplete-test "--root")
171 (pcomplete-here* (pcomplete-dirs)))
172 ((pcomplete-test "--rcfile")
173 (pcomplete-here* (pcomplete-entries)))))
174 (if (pcomplete-match "^-" 0)
177 ((memq mode
'(install upgrade
))
178 (if (pcomplete-match "^--\\(.*\\)" 0)
198 (if (eq mode
'upgrade
)
208 ((pcomplete-test "--dbpath")
209 (pcomplete-here* (pcomplete-dirs)))
210 ((pcomplete-test "--relocate")
212 ((pcomplete-test "--rcfile")
213 (pcomplete-here* (pcomplete-entries)))
214 ((pcomplete-test "--excludepath")
215 (pcomplete-here* (pcomplete-entries)))
216 ((pcomplete-test "--root")
217 (pcomplete-here* (pcomplete-dirs)))
218 ((pcomplete-test "--prefix")
219 (pcomplete-here* (pcomplete-dirs)))))
220 (if (pcomplete-match "^-" 0)
222 (pcomplete-here (pcmpl-rpm-files)))))
223 ((or (pcomplete-test "--install")
224 (pcomplete-match "-[^-]*i"))
225 (setq mode
'install
))
226 ((or (pcomplete-test "--upgrade")
227 (pcomplete-match "-[^-]*U"))
228 (setq mode
'upgrade
))
229 ((or (eq mode
'erase
)
230 (pcomplete-test "--erase")
231 (pcomplete-match "-[^-]*e"))
233 (if (pcomplete-match "^--\\(.*\\)" 0)
246 ((pcomplete-test "--dbpath")
247 (pcomplete-here* (pcomplete-dirs)))
248 ((pcomplete-test "--rcfile")
249 (pcomplete-here* (pcomplete-entries)))
250 ((pcomplete-test "--root")
251 (pcomplete-here* (pcomplete-dirs)))))
252 (if (pcomplete-match "^-" 0)
254 (pcomplete-here (pcmpl-rpm-packages)))))
255 ((or (eq mode
'verify
)
256 (pcomplete-test "--verify"))
258 (if (pcomplete-match "^--\\(.*\\)" 0)
271 ((pcomplete-test "--dbpath")
272 (pcomplete-here* (pcomplete-dirs)))
273 ((pcomplete-test "--rcfile")
274 (pcomplete-here* (pcomplete-entries)))
275 ((pcomplete-test "--root")
276 (pcomplete-here* (pcomplete-dirs)))
277 ((pcomplete-test "--triggeredby")
278 (pcomplete-here* (pcmpl-rpm-packages)))
279 ((pcomplete-test "--whatprovides")
281 (pcmpl-rpm-all-query "--provides")))
282 ((pcomplete-test "--whatrequires")
284 (pcmpl-rpm-all-query "--requires")))))
285 (if (pcomplete-match "^-" 0)
286 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
287 (pcomplete-here (pcmpl-rpm-packages)))))
288 ((or (memq mode
'(build test
))
289 (pcomplete-match "\\`-[bt]"))
290 (setq mode
(if (pcomplete-match "\\`-b")
293 (if (pcomplete-match "^--\\(.*\\)" 0)
306 ((pcomplete-test "--buildroot")
307 (pcomplete-here* (pcomplete-dirs)))
308 ((pcomplete-test "--rcfile")
309 (pcomplete-here* (pcomplete-entries)))
310 ((pcomplete-test "--timecheck")
312 (if (pcomplete-match "^-" 0)
316 (pcomplete-dirs-or-entries "\\.tar\\'")
317 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
319 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
323 ;; arch-tag: 4e64b490-fecf-430e-b2b9-70a8ad64b8c1
324 ;;; pcmpl-rpm.el ends here