1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999-2011 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.
32 (defsubst pcmpl-rpm-packages
()
33 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
35 (defun pcmpl-rpm-all-query (flag)
36 (message "Querying all packages with `%s'..." flag
)
37 (let ((pkgs (pcmpl-rpm-packages))
40 (nconc provs
(split-string
41 (pcomplete-process-result
42 "rpm" "-q" (car pkgs
) flag
)))
43 (setq pkgs
(cdr pkgs
)))
44 (pcomplete-uniqify-list (cdr provs
))))
46 (defsubst pcmpl-rpm-files
()
47 (pcomplete-dirs-or-entries "\\.rpm\\'"))
50 (defun pcomplete/rpm
()
51 "Completion for the `rpm' command."
52 ;; Originally taken from the output of `rpm --help' on a Red Hat 6.1 system.
54 (while (<= pcomplete-index pcomplete-last
)
56 (if (pcomplete-match "^--\\(.*\\)" 0)
76 (pcomplete-opt "vqVyiUebtK")))
78 ; -t<stage> <tarball> - build package, where <stage> is one of:
79 ; p - prep (unpack sources and apply patches)
80 ; l - list check (do some cursory checks on %files)
81 ; c - compile (prep and compile)
82 ; i - install (prep, compile, install)
83 ; b - binary package (prep, compile, install, package)
84 ; a - bin/src package (prep, compile, install, package)
87 (pcomplete-match "-[^-]*q"))
89 (if (pcomplete-match "^--\\(.*\\)" 0)
95 "--ftpport" ;nyi for the next four
109 ((pcomplete-test "--dbpath")
110 (pcomplete-here* (pcomplete-dirs)))
111 ((pcomplete-test "--queryformat")
113 ((pcomplete-test "--rcfile")
114 (pcomplete-here* (pcomplete-entries)))
115 ((pcomplete-test "--root")
116 (pcomplete-here* (pcomplete-dirs)))
117 ((pcomplete-test "--scripts")
118 (if (pcomplete-match "^--\\(.*\\)" 0)
119 (pcomplete-here* '("--triggers"))))
120 ((pcomplete-test "--triggeredby")
121 (pcomplete-here* (pcmpl-rpm-packages)))
122 ((pcomplete-test "--whatprovides")
124 (pcmpl-rpm-all-query "--provides")))
125 ((pcomplete-test "--whatrequires")
127 (pcmpl-rpm-all-query "--requires")))))
128 (if (pcomplete-match "^-" 0)
129 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
130 (if (pcomplete-test "-[^-]*p" 'first
1)
131 (pcomplete-here (pcmpl-rpm-files))
132 (pcomplete-here (pcmpl-rpm-packages))))))
133 ((pcomplete-test "--pipe")
134 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
135 ((pcomplete-test "--rmsource")
136 (pcomplete-here* (pcomplete-entries))
137 (throw 'pcomplete-completions nil
))
138 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
139 (pcomplete-here (pcmpl-rpm-files))
140 (throw 'pcomplete-completions nil
))
141 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
142 (while (pcomplete-here (pcmpl-rpm-files))))
143 ((or (eq mode
'checksig
)
144 (pcomplete-test "--checksig"))
145 (setq mode
'checksig
)
146 (if (pcomplete-match "^--\\(.*\\)" 0)
154 ((pcomplete-test "--rcfile")
155 (pcomplete-here* (pcomplete-entries)))))
156 (if (pcomplete-match "^-" 0)
158 (pcomplete-here (pcmpl-rpm-files)))))
159 ((or (eq mode
'rebuilddb
)
160 (pcomplete-test "--rebuilddb"))
161 (setq mode
'rebuilddb
)
162 (if (pcomplete-match "^--\\(.*\\)" 0)
169 ((pcomplete-test "--dbpath")
170 (pcomplete-here* (pcomplete-dirs)))
171 ((pcomplete-test "--root")
172 (pcomplete-here* (pcomplete-dirs)))
173 ((pcomplete-test "--rcfile")
174 (pcomplete-here* (pcomplete-entries)))))
175 (if (pcomplete-match "^-" 0)
178 ((memq mode
'(install upgrade
))
179 (if (pcomplete-match "^--\\(.*\\)" 0)
199 (if (eq mode
'upgrade
)
209 ((pcomplete-test "--dbpath")
210 (pcomplete-here* (pcomplete-dirs)))
211 ((pcomplete-test "--relocate")
213 ((pcomplete-test "--rcfile")
214 (pcomplete-here* (pcomplete-entries)))
215 ((pcomplete-test "--excludepath")
216 (pcomplete-here* (pcomplete-entries)))
217 ((pcomplete-test "--root")
218 (pcomplete-here* (pcomplete-dirs)))
219 ((pcomplete-test "--prefix")
220 (pcomplete-here* (pcomplete-dirs)))))
221 (if (pcomplete-match "^-" 0)
223 (pcomplete-here (pcmpl-rpm-files)))))
224 ((or (pcomplete-test "--install")
225 (pcomplete-match "-[^-]*i"))
226 (setq mode
'install
))
227 ((or (pcomplete-test "--upgrade")
228 (pcomplete-match "-[^-]*U"))
229 (setq mode
'upgrade
))
230 ((or (eq mode
'erase
)
231 (pcomplete-test "--erase")
232 (pcomplete-match "-[^-]*e"))
234 (if (pcomplete-match "^--\\(.*\\)" 0)
247 ((pcomplete-test "--dbpath")
248 (pcomplete-here* (pcomplete-dirs)))
249 ((pcomplete-test "--rcfile")
250 (pcomplete-here* (pcomplete-entries)))
251 ((pcomplete-test "--root")
252 (pcomplete-here* (pcomplete-dirs)))))
253 (if (pcomplete-match "^-" 0)
255 (pcomplete-here (pcmpl-rpm-packages)))))
256 ((or (eq mode
'verify
)
257 (pcomplete-test "--verify"))
259 (if (pcomplete-match "^--\\(.*\\)" 0)
272 ((pcomplete-test "--dbpath")
273 (pcomplete-here* (pcomplete-dirs)))
274 ((pcomplete-test "--rcfile")
275 (pcomplete-here* (pcomplete-entries)))
276 ((pcomplete-test "--root")
277 (pcomplete-here* (pcomplete-dirs)))
278 ((pcomplete-test "--triggeredby")
279 (pcomplete-here* (pcmpl-rpm-packages)))
280 ((pcomplete-test "--whatprovides")
282 (pcmpl-rpm-all-query "--provides")))
283 ((pcomplete-test "--whatrequires")
285 (pcmpl-rpm-all-query "--requires")))))
286 (if (pcomplete-match "^-" 0)
287 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
288 (pcomplete-here (pcmpl-rpm-packages)))))
289 ((or (memq mode
'(build test
))
290 (pcomplete-match "\\`-[bt]"))
291 (setq mode
(if (pcomplete-match "\\`-b")
294 (if (pcomplete-match "^--\\(.*\\)" 0)
307 ((pcomplete-test "--buildroot")
308 (pcomplete-here* (pcomplete-dirs)))
309 ((pcomplete-test "--rcfile")
310 (pcomplete-here* (pcomplete-entries)))
311 ((pcomplete-test "--timecheck")
313 (if (pcomplete-match "^-" 0)
317 (pcomplete-dirs-or-entries "\\.tar\\'")
318 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
320 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
324 ;;; pcmpl-rpm.el ends here