Mercurial > emacs
annotate lisp/pcmpl-unix.el @ 88123:375f2633d815
New directory
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 08 Sep 2003 11:56:09 +0000 |
parents | 695cf19ef79e |
children | 68c22ea6027c |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29959
diff
changeset
|
1 ;;; pcmpl-unix.el --- standard UNIX completions |
29959 | 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 | |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29959
diff
changeset
|
22 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29959
diff
changeset
|
23 |
29959 | 24 ;;; Code: |
25 | |
26 (provide 'pcmpl-unix) | |
27 | |
28 (require 'pcomplete) | |
29 | |
30 ;; User Variables: | |
31 | |
32 (defcustom pcmpl-unix-group-file "/etc/group" | |
33 "*If non-nil, a string naming the group file on your system." | |
34 :type 'file | |
35 :group 'pcmpl-unix) | |
36 | |
37 (defcustom pcmpl-unix-passwd-file "/etc/passwd" | |
38 "*If non-nil, a string naming the passwd file on your system." | |
39 :type 'file | |
40 :group 'pcmpl-unix) | |
41 | |
42 ;; Functions: | |
43 | |
44 ;;;###autoload | |
45 (defun pcomplete/cd () | |
46 "Completion for `cd'." | |
47 (pcomplete-here (pcomplete-dirs))) | |
48 | |
49 ;;;###autoload | |
50 (defalias 'pcomplete/pushd 'pcomplete/cd) | |
51 | |
52 ;;;###autoload | |
53 (defun pcomplete/rmdir () | |
54 "Completion for `rmdir'." | |
55 (while (pcomplete-here (pcomplete-dirs)))) | |
56 | |
57 ;;;###autoload | |
58 (defun pcomplete/rm () | |
59 "Completion for `rm'." | |
60 (let ((pcomplete-help "(fileutils)rm invocation")) | |
61 (pcomplete-opt "dfirRv") | |
62 (while (pcomplete-here (pcomplete-all-entries) nil | |
63 'expand-file-name)))) | |
64 | |
65 ;;;###autoload | |
66 (defun pcomplete/xargs () | |
67 "Completion for `xargs'." | |
68 (pcomplete-here (funcall pcomplete-command-completion-function)) | |
69 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
70 pcomplete-default-completion-function))) | |
71 | |
72 ;;;###autoload | |
73 (defalias 'pcomplete/time 'pcomplete/xargs) | |
74 | |
75 ;;;###autoload | |
76 (defun pcomplete/which () | |
77 "Completion for `which'." | |
78 (while (pcomplete-here (funcall pcomplete-command-completion-function)))) | |
79 | |
80 (defun pcmpl-unix-read-passwd-file (file) | |
81 "Return an alist correlating gids to group names in FILE." | |
82 (let (names) | |
83 (when (file-readable-p file) | |
84 (with-temp-buffer | |
85 (insert-file-contents file) | |
86 (goto-char (point-min)) | |
87 (while (not (eobp)) | |
88 (let* ((fields | |
89 (split-string (buffer-substring | |
90 (point) (progn (end-of-line) | |
91 (point))) ":"))) | |
92 (setq names (cons (nth 0 fields) names))) | |
93 (forward-line)))) | |
94 (pcomplete-uniqify-list names))) | |
95 | |
96 (defsubst pcmpl-unix-group-names () | |
97 "Read the contents of /etc/group for group names." | |
98 (if pcmpl-unix-group-file | |
99 (pcmpl-unix-read-passwd-file pcmpl-unix-group-file))) | |
100 | |
101 (defsubst pcmpl-unix-user-names () | |
102 "Read the contents of /etc/passwd for user names." | |
103 (if pcmpl-unix-passwd-file | |
104 (pcmpl-unix-read-passwd-file pcmpl-unix-passwd-file))) | |
105 | |
106 ;;;###autoload | |
107 (defun pcomplete/chown () | |
108 "Completion for the `chown' command." | |
109 (unless (pcomplete-match "\\`-") | |
110 (if (pcomplete-match "\\`[^.]*\\'" 0) | |
111 (pcomplete-here* (pcmpl-unix-user-names)) | |
112 (if (pcomplete-match "\\.\\([^.]*\\)\\'" 0) | |
113 (pcomplete-here* (pcmpl-unix-group-names) | |
114 (pcomplete-match-string 1 0)) | |
115 (pcomplete-here*)))) | |
116 (while (pcomplete-here (pcomplete-entries)))) | |
117 | |
118 ;;;###autoload | |
119 (defun pcomplete/chgrp () | |
120 "Completion for the `chgrp' command." | |
121 (unless (pcomplete-match "\\`-") | |
122 (pcomplete-here* (pcmpl-unix-group-names))) | |
123 (while (pcomplete-here (pcomplete-entries)))) | |
124 | |
125 ;;; pcmpl-unix.el ends here |