1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; These functions provide completion rules for the `rpm' command.
30 (defgroup pcmpl-rpm nil
31 "Options for rpm completion."
35 ;; rpm -qa can be slow. Adding --nodigest --nosignature is MUCH faster.
36 (defcustom pcmpl-rpm-query-options
39 (when (ignore-errors (call-process "rpm" nil t nil
"--help"))
40 (if (search-backward "--nodigest " nil
'move
)
41 (setq opts
'("--nodigest")))
42 (goto-char (point-min))
43 (if (search-forward "--nosignature " nil t
)
44 (push "--nosignature" opts
))))
46 "List of extra options to add to an rpm query command."
48 :type
'(repeat string
)
54 ;; This can be slow, so:
55 ;; Consider caching the result (cf woman).
56 ;; Consider printing an explanatory message before running -qa.
57 (defun pcmpl-rpm-packages ()
58 "Return a list of all installed rpm packages."
59 (split-string (apply 'pcomplete-process-result
"rpm"
60 (append '("-q" "-a") pcmpl-rpm-query-options
))))
62 ;; Should this use pcmpl-rpm-query-options?
63 ;; I don't think it would speed it up at all (?).
64 (defun pcmpl-rpm-all-query (flag)
65 (message "Querying all packages with `%s'..." flag
)
66 (let ((pkgs (pcmpl-rpm-packages))
69 (nconc provs
(split-string
70 (pcomplete-process-result
71 "rpm" "-q" (car pkgs
) flag
)))
72 (setq pkgs
(cdr pkgs
)))
73 (pcomplete-uniqify-list (cdr provs
))))
75 (defsubst pcmpl-rpm-files
()
76 (pcomplete-dirs-or-entries "\\.rpm\\'"))
79 (defun pcomplete/rpm
()
80 "Completion for the `rpm' command."
81 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
83 (while (<= pcomplete-index pcomplete-last
)
85 (if (pcomplete-match "^--\\(.*\\)" 0)
105 (pcomplete-opt "vqVyiUebtK")))
107 ; -t<stage> <tarball> - build package, where <stage> is one of:
108 ; p - prep (unpack sources and apply patches)
109 ; l - list check (do some cursory checks on %files)
110 ; c - compile (prep and compile)
111 ; i - install (prep, compile, install)
112 ; b - binary package (prep, compile, install, package)
113 ; a - bin/src package (prep, compile, install, package)
115 ((or (eq mode
'query
)
116 (pcomplete-match "-[^-]*q"))
118 (if (pcomplete-match "^--\\(.*\\)" 0)
125 "--ftpport" ;nyi for the next four
139 ((pcomplete-test "--dbpath")
140 (pcomplete-here* (pcomplete-dirs)))
141 ((pcomplete-test "--queryformat")
143 ((pcomplete-test "--rcfile")
144 (pcomplete-here* (pcomplete-entries)))
145 ((pcomplete-test "--file")
146 (pcomplete-here* (pcomplete-entries)))
147 ((pcomplete-test "--root")
148 (pcomplete-here* (pcomplete-dirs)))
149 ((pcomplete-test "--scripts")
150 (if (pcomplete-match "^--\\(.*\\)" 0)
151 (pcomplete-here* '("--triggers"))))
152 ((pcomplete-test "--triggeredby")
153 (pcomplete-here* (pcmpl-rpm-packages)))
154 ((pcomplete-test "--whatprovides")
156 (pcmpl-rpm-all-query "--provides")))
157 ((pcomplete-test "--whatrequires")
159 (pcmpl-rpm-all-query "--requires")))))
160 (if (pcomplete-match "^-" 0)
161 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
162 (if (pcomplete-test "-[^-]*p" 'first
1)
163 (pcomplete-here (pcmpl-rpm-files))
164 (if (pcomplete-test "-[^-]*f" 'first
1)
165 (pcomplete-here* (pcomplete-entries))
166 (pcomplete-here (pcmpl-rpm-packages)))))))
167 ((pcomplete-test "--pipe")
168 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
169 ((pcomplete-test "--rmsource")
170 (pcomplete-here* (pcomplete-entries))
171 (throw 'pcomplete-completions nil
))
172 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
173 (pcomplete-here (pcmpl-rpm-files))
174 (throw 'pcomplete-completions nil
))
175 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
176 (while (pcomplete-here (pcmpl-rpm-files))))
177 ((or (eq mode
'checksig
)
178 (pcomplete-test "--checksig"))
179 (setq mode
'checksig
)
180 (if (pcomplete-match "^--\\(.*\\)" 0)
188 ((pcomplete-test "--rcfile")
189 (pcomplete-here* (pcomplete-entries)))))
190 (if (pcomplete-match "^-" 0)
192 (pcomplete-here (pcmpl-rpm-files)))))
193 ((or (eq mode
'rebuilddb
)
194 (pcomplete-test "--rebuilddb"))
195 (setq mode
'rebuilddb
)
196 (if (pcomplete-match "^--\\(.*\\)" 0)
203 ((pcomplete-test "--dbpath")
204 (pcomplete-here* (pcomplete-dirs)))
205 ((pcomplete-test "--root")
206 (pcomplete-here* (pcomplete-dirs)))
207 ((pcomplete-test "--rcfile")
208 (pcomplete-here* (pcomplete-entries)))))
209 (if (pcomplete-match "^-" 0)
212 ((memq mode
'(install upgrade
))
213 (if (pcomplete-match "^--\\(.*\\)" 0)
233 (if (eq mode
'upgrade
)
243 ((pcomplete-test "--dbpath")
244 (pcomplete-here* (pcomplete-dirs)))
245 ((pcomplete-test "--relocate")
247 ((pcomplete-test "--rcfile")
248 (pcomplete-here* (pcomplete-entries)))
249 ((pcomplete-test "--excludepath")
250 (pcomplete-here* (pcomplete-entries)))
251 ((pcomplete-test "--root")
252 (pcomplete-here* (pcomplete-dirs)))
253 ((pcomplete-test "--prefix")
254 (pcomplete-here* (pcomplete-dirs)))))
255 (if (pcomplete-match "^-" 0)
257 (pcomplete-here (pcmpl-rpm-files)))))
258 ((or (pcomplete-test "--install")
259 (pcomplete-match "-[^-]*i"))
260 (setq mode
'install
))
261 ((or (pcomplete-test "--upgrade")
262 (pcomplete-match "-[^-]*U"))
263 (setq mode
'upgrade
))
264 ((or (eq mode
'erase
)
265 (pcomplete-test "--erase")
266 (pcomplete-match "-[^-]*e"))
268 (if (pcomplete-match "^--\\(.*\\)" 0)
281 ((pcomplete-test "--dbpath")
282 (pcomplete-here* (pcomplete-dirs)))
283 ((pcomplete-test "--rcfile")
284 (pcomplete-here* (pcomplete-entries)))
285 ((pcomplete-test "--root")
286 (pcomplete-here* (pcomplete-dirs)))))
287 (if (pcomplete-match "^-" 0)
289 (pcomplete-here (pcmpl-rpm-packages)))))
290 ((or (eq mode
'verify
)
291 (pcomplete-test "--verify"))
293 (if (pcomplete-match "^--\\(.*\\)" 0)
306 ((pcomplete-test "--dbpath")
307 (pcomplete-here* (pcomplete-dirs)))
308 ((pcomplete-test "--rcfile")
309 (pcomplete-here* (pcomplete-entries)))
310 ((pcomplete-test "--root")
311 (pcomplete-here* (pcomplete-dirs)))
312 ((pcomplete-test "--triggeredby")
313 (pcomplete-here* (pcmpl-rpm-packages)))
314 ((pcomplete-test "--whatprovides")
316 (pcmpl-rpm-all-query "--provides")))
317 ((pcomplete-test "--whatrequires")
319 (pcmpl-rpm-all-query "--requires")))))
320 (if (pcomplete-match "^-" 0)
321 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
322 (pcomplete-here (pcmpl-rpm-packages)))))
323 ((or (memq mode
'(build test
))
324 (pcomplete-match "\\`-[bt]"))
325 (setq mode
(if (pcomplete-match "\\`-b")
328 (if (pcomplete-match "^--\\(.*\\)" 0)
341 ((pcomplete-test "--buildroot")
342 (pcomplete-here* (pcomplete-dirs)))
343 ((pcomplete-test "--rcfile")
344 (pcomplete-here* (pcomplete-entries)))
345 ((pcomplete-test "--timecheck")
347 (if (pcomplete-match "^-" 0)
350 (pcomplete-dirs-or-entries (if (eq mode
'test
)
354 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
358 ;;; pcmpl-rpm.el ends here