Commit | Line | Data |
---|---|---|
4fa9f636 GM |
1 | ;;; pcmpl-unix --- standard UNIX completions |
2 | ||
3 | ;; Copyright (C) 1999, 2000 Free Software Foundation | |
4 | ||
5 | ;; This file is part of GNU Emacs. | |
6 | ||
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) | |
10 | ;; any later version. | |
11 | ||
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. | |
16 | ||
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. | |
21 | ||
22 | ;;; Code: | |
23 | ||
24 | (provide 'pcmpl-unix) | |
25 | ||
26 | (require 'pcomplete) | |
27 | ||
28 | ;; User Variables: | |
29 | ||
30 | (defcustom pcmpl-unix-group-file "/etc/group" | |
31 | "*If non-nil, a string naming the group file on your system." | |
32 | :type 'file | |
33 | :group 'pcmpl-unix) | |
34 | ||
35 | (defcustom pcmpl-unix-passwd-file "/etc/passwd" | |
36 | "*If non-nil, a string naming the passwd file on your system." | |
37 | :type 'file | |
38 | :group 'pcmpl-unix) | |
39 | ||
40 | ;; Functions: | |
41 | ||
42 | ;;;###autoload | |
43 | (defun pcomplete/cd () | |
44 | "Completion for `cd'." | |
45 | (pcomplete-here (pcomplete-dirs))) | |
46 | ||
47 | ;;;###autoload | |
48 | (defalias 'pcomplete/pushd 'pcomplete/cd) | |
49 | ||
50 | ;;;###autoload | |
51 | (defun pcomplete/rmdir () | |
52 | "Completion for `rmdir'." | |
53 | (while (pcomplete-here (pcomplete-dirs)))) | |
54 | ||
55 | ;;;###autoload | |
56 | (defun pcomplete/rm () | |
57 | "Completion for `rm'." | |
58 | (let ((pcomplete-help "(fileutils)rm invocation")) | |
59 | (pcomplete-opt "dfirRv") | |
60 | (while (pcomplete-here (pcomplete-all-entries) nil | |
61 | 'expand-file-name)))) | |
62 | ||
63 | ;;;###autoload | |
64 | (defun pcomplete/xargs () | |
65 | "Completion for `xargs'." | |
66 | (pcomplete-here (funcall pcomplete-command-completion-function)) | |
67 | (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
68 | pcomplete-default-completion-function))) | |
69 | ||
70 | ;;;###autoload | |
71 | (defalias 'pcomplete/time 'pcomplete/xargs) | |
72 | ||
73 | ;;;###autoload | |
74 | (defun pcomplete/which () | |
75 | "Completion for `which'." | |
76 | (while (pcomplete-here (funcall pcomplete-command-completion-function)))) | |
77 | ||
78 | (defun pcmpl-unix-read-passwd-file (file) | |
79 | "Return an alist correlating gids to group names in FILE." | |
80 | (let (names) | |
81 | (when (file-readable-p file) | |
82 | (with-temp-buffer | |
83 | (insert-file-contents file) | |
84 | (goto-char (point-min)) | |
85 | (while (not (eobp)) | |
86 | (let* ((fields | |
87 | (split-string (buffer-substring | |
88 | (point) (progn (end-of-line) | |
89 | (point))) ":"))) | |
90 | (setq names (cons (nth 0 fields) names))) | |
91 | (forward-line)))) | |
92 | (pcomplete-uniqify-list names))) | |
93 | ||
94 | (defsubst pcmpl-unix-group-names () | |
95 | "Read the contents of /etc/group for group names." | |
96 | (if pcmpl-unix-group-file | |
97 | (pcmpl-unix-read-passwd-file pcmpl-unix-group-file))) | |
98 | ||
99 | (defsubst pcmpl-unix-user-names () | |
100 | "Read the contents of /etc/passwd for user names." | |
101 | (if pcmpl-unix-passwd-file | |
102 | (pcmpl-unix-read-passwd-file pcmpl-unix-passwd-file))) | |
103 | ||
104 | ;;;###autoload | |
105 | (defun pcomplete/chown () | |
106 | "Completion for the `chown' command." | |
107 | (unless (pcomplete-match "\\`-") | |
108 | (if (pcomplete-match "\\`[^.]*\\'" 0) | |
109 | (pcomplete-here* (pcmpl-unix-user-names)) | |
110 | (if (pcomplete-match "\\.\\([^.]*\\)\\'" 0) | |
111 | (pcomplete-here* (pcmpl-unix-group-names) | |
112 | (pcomplete-match-string 1 0)) | |
113 | (pcomplete-here*)))) | |
114 | (while (pcomplete-here (pcomplete-entries)))) | |
115 | ||
116 | ;;;###autoload | |
117 | (defun pcomplete/chgrp () | |
118 | "Completion for the `chgrp' command." | |
119 | (unless (pcomplete-match "\\`-") | |
120 | (pcomplete-here* (pcmpl-unix-group-names))) | |
121 | (while (pcomplete-here (pcomplete-entries)))) | |
122 | ||
123 | ;;; pcmpl-unix.el ends here |