1 ;;; pcmpl-rpm.el --- functions for dealing with rpm completions
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
24 ;; These functions provide completion rules for RedHat's `rpm' tool.
32 (defgroup pcmpl-rpm nil
33 "Functions for dealing with CVS completions"
38 (defsubst pcmpl-rpm-packages
()
39 (split-string (pcomplete-process-result "rpm" "-q" "-a")))
41 (defun pcmpl-rpm-all-query (flag)
42 (message "Querying all packages with `%s'..." flag
)
43 (let ((pkgs (pcmpl-rpm-packages))
46 (nconc provs
(split-string
47 (pcomplete-process-result
48 "rpm" "-q" (car pkgs
) flag
)))
49 (setq pkgs
(cdr pkgs
)))
50 (pcomplete-uniqify-list (cdr provs
))))
52 (defsubst pcmpl-rpm-files
()
53 (pcomplete-dirs-or-entries "\\.rpm\\'"))
56 (defun pcomplete/rpm
()
57 "Completion for RedHat's `rpm' command.
58 These rules were taken from the output of `rpm --help' on a RedHat 6.1
59 system. They follow my interpretation of what followed, but since I'm
60 not a major rpm user/builder, please send me any corrections you find.
61 You can use \\[eshell-report-bug] to do so."
63 (while (<= pcomplete-index pcomplete-last
)
65 (if (pcomplete-match "^--\\(.*\\)" 0)
85 (pcomplete-opt "vqVyiUebtK")))
87 ; -t<stage> <tarball> - build package, where <stage> is one of:
88 ; p - prep (unpack sources and apply patches)
89 ; l - list check (do some cursory checks on %files)
90 ; c - compile (prep and compile)
91 ; i - install (prep, compile, install)
92 ; b - binary package (prep, compile, install, package)
93 ; a - bin/src package (prep, compile, install, package)
96 (pcomplete-match "-[^-]*q"))
98 (if (pcomplete-match "^--\\(.*\\)" 0)
104 "--ftpport" ;nyi for the next four
118 ((pcomplete-test "--dbpath")
119 (pcomplete-here* (pcomplete-dirs)))
120 ((pcomplete-test "--queryformat")
122 ((pcomplete-test "--rcfile")
123 (pcomplete-here* (pcomplete-entries)))
124 ((pcomplete-test "--root")
125 (pcomplete-here* (pcomplete-dirs)))
126 ((pcomplete-test "--scripts")
127 (if (pcomplete-match "^--\\(.*\\)" 0)
128 (pcomplete-here* '("--triggers"))))
129 ((pcomplete-test "--triggeredby")
130 (pcomplete-here* (pcmpl-rpm-packages)))
131 ((pcomplete-test "--whatprovides")
133 (pcmpl-rpm-all-query "--provides")))
134 ((pcomplete-test "--whatrequires")
136 (pcmpl-rpm-all-query "--requires")))))
137 (if (pcomplete-match "^-" 0)
138 (pcomplete-opt "af.p(pcmpl-rpm-files)ilsdcvR")
139 (pcomplete-here (pcmpl-rpm-packages)))))
140 ((pcomplete-test "--pipe")
141 (pcomplete-here* (funcall pcomplete-command-completion-function
)))
142 ((pcomplete-test "--rmsource")
143 (pcomplete-here* (pcomplete-entries))
144 (throw 'pcomplete-completions nil
))
145 ((pcomplete-match "\\`--re\\(build\\|compile\\)\\'")
146 (pcomplete-here (pcmpl-rpm-files))
147 (throw 'pcomplete-completions nil
))
148 ((pcomplete-match "\\`--\\(resign\\|addsign\\)\\'")
149 (while (pcomplete-here (pcmpl-rpm-files))))
150 ((or (eq mode
'checksig
)
151 (pcomplete-test "--checksig"))
152 (setq mode
'checksig
)
153 (if (pcomplete-match "^--\\(.*\\)" 0)
161 ((pcomplete-test "--rcfile")
162 (pcomplete-here* (pcomplete-entries)))))
163 (if (pcomplete-match "^-" 0)
165 (pcomplete-here (pcmpl-rpm-files)))))
166 ((or (eq mode
'rebuilddb
)
167 (pcomplete-test "--rebuilddb"))
168 (setq mode
'rebuilddb
)
169 (if (pcomplete-match "^--\\(.*\\)" 0)
176 ((pcomplete-test "--dbpath")
177 (pcomplete-here* (pcomplete-dirs)))
178 ((pcomplete-test "--root")
179 (pcomplete-here* (pcomplete-dirs)))
180 ((pcomplete-test "--rcfile")
181 (pcomplete-here* (pcomplete-entries)))))
182 (if (pcomplete-match "^-" 0)
185 ((memq mode
'(install upgrade
))
186 (if (pcomplete-match "^--\\(.*\\)" 0)
206 (if (eq mode
'upgrade
)
216 ((pcomplete-test "--dbpath")
217 (pcomplete-here* (pcomplete-dirs)))
218 ((pcomplete-test "--relocate")
220 ((pcomplete-test "--rcfile")
221 (pcomplete-here* (pcomplete-entries)))
222 ((pcomplete-test "--excludepath")
223 (pcomplete-here* (pcomplete-entries)))
224 ((pcomplete-test "--root")
225 (pcomplete-here* (pcomplete-dirs)))
226 ((pcomplete-test "--prefix")
227 (pcomplete-here* (pcomplete-dirs)))))
228 (if (pcomplete-match "^-" 0)
230 (pcomplete-here (pcmpl-rpm-files)))))
231 ((or (pcomplete-test "--install")
232 (pcomplete-match "-[^-]*i"))
233 (setq mode
'install
))
234 ((or (pcomplete-test "--upgrade")
235 (pcomplete-match "-[^-]*U"))
236 (setq mode
'upgrade
))
237 ((or (eq mode
'erase
)
238 (pcomplete-test "--erase")
239 (pcomplete-match "-[^-]*e"))
241 (if (pcomplete-match "^--\\(.*\\)" 0)
254 ((pcomplete-test "--dbpath")
255 (pcomplete-here* (pcomplete-dirs)))
256 ((pcomplete-test "--rcfile")
257 (pcomplete-here* (pcomplete-entries)))
258 ((pcomplete-test "--root")
259 (pcomplete-here* (pcomplete-dirs)))))
260 (if (pcomplete-match "^-" 0)
262 (pcomplete-here (pcmpl-rpm-packages)))))
263 ((or (eq mode
'verify
)
264 (pcomplete-test "--verify"))
266 (if (pcomplete-match "^--\\(.*\\)" 0)
279 ((pcomplete-test "--dbpath")
280 (pcomplete-here* (pcomplete-dirs)))
281 ((pcomplete-test "--rcfile")
282 (pcomplete-here* (pcomplete-entries)))
283 ((pcomplete-test "--root")
284 (pcomplete-here* (pcomplete-dirs)))
285 ((pcomplete-test "--triggeredby")
286 (pcomplete-here* (pcmpl-rpm-packages)))
287 ((pcomplete-test "--whatprovides")
289 (pcmpl-rpm-all-query "--provides")))
290 ((pcomplete-test "--whatrequires")
292 (pcmpl-rpm-all-query "--requires")))))
293 (if (pcomplete-match "^-" 0)
294 (pcomplete-opt "af.p(pcmpl-rpm-files)v")
295 (pcomplete-here (pcmpl-rpm-packages)))))
296 ((or (memq mode
'(build test
))
297 (pcomplete-match "\\`-[bt]"))
298 (setq mode
(if (pcomplete-match "\\`-b")
301 (if (pcomplete-match "^--\\(.*\\)" 0)
314 ((pcomplete-test "--buildroot")
315 (pcomplete-here* (pcomplete-dirs)))
316 ((pcomplete-test "--rcfile")
317 (pcomplete-here* (pcomplete-entries)))
318 ((pcomplete-test "--timecheck")
320 (if (pcomplete-match "^-" 0)
324 (pcomplete-dirs-or-entries "\\.tar\\'")
325 (pcomplete-dirs-or-entries "\\.spec\\'"))))))
327 (error "You must select a mode: -q, -i, -U, --verify, etc"))))))
329 ;;; pcmpl-rpm.el ends here