Mercurial > emacs
annotate lisp/pcmpl-unix.el @ 76612:5cccae6f9cfa
Dired reference cards regenerated for Emacs 22; no changed keybindings found.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 19 Mar 2007 23:16:15 +0000 |
parents | e3694f1cb928 |
children | 9355f9b7bbff 95d0cdf160ea |
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 |
74442 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
29959 | 5 |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 ;; Boston, MA 02110-1301, USA. | |
29959 | 22 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29959
diff
changeset
|
23 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
29959
diff
changeset
|
24 |
29959 | 25 ;;; Code: |
26 | |
27 (provide 'pcmpl-unix) | |
28 | |
29 (require 'pcomplete) | |
30 | |
31 ;; User Variables: | |
32 | |
33 (defcustom pcmpl-unix-group-file "/etc/group" | |
34 "*If non-nil, a string naming the group file on your system." | |
35 :type 'file | |
36 :group 'pcmpl-unix) | |
37 | |
38 (defcustom pcmpl-unix-passwd-file "/etc/passwd" | |
39 "*If non-nil, a string naming the passwd file on your system." | |
40 :type 'file | |
41 :group 'pcmpl-unix) | |
42 | |
43 ;; Functions: | |
44 | |
45 ;;;###autoload | |
46 (defun pcomplete/cd () | |
47 "Completion for `cd'." | |
48 (pcomplete-here (pcomplete-dirs))) | |
49 | |
50 ;;;###autoload | |
51 (defalias 'pcomplete/pushd 'pcomplete/cd) | |
52 | |
53 ;;;###autoload | |
54 (defun pcomplete/rmdir () | |
55 "Completion for `rmdir'." | |
56 (while (pcomplete-here (pcomplete-dirs)))) | |
57 | |
58 ;;;###autoload | |
59 (defun pcomplete/rm () | |
60 "Completion for `rm'." | |
61 (let ((pcomplete-help "(fileutils)rm invocation")) | |
62 (pcomplete-opt "dfirRv") | |
63 (while (pcomplete-here (pcomplete-all-entries) nil | |
64 'expand-file-name)))) | |
65 | |
66 ;;;###autoload | |
67 (defun pcomplete/xargs () | |
68 "Completion for `xargs'." | |
69 (pcomplete-here (funcall pcomplete-command-completion-function)) | |
70 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
71 pcomplete-default-completion-function))) | |
72 | |
73 ;;;###autoload | |
74 (defalias 'pcomplete/time 'pcomplete/xargs) | |
75 | |
76 ;;;###autoload | |
77 (defun pcomplete/which () | |
78 "Completion for `which'." | |
79 (while (pcomplete-here (funcall pcomplete-command-completion-function)))) | |
80 | |
81 (defun pcmpl-unix-read-passwd-file (file) | |
82 "Return an alist correlating gids to group names in FILE." | |
83 (let (names) | |
84 (when (file-readable-p file) | |
85 (with-temp-buffer | |
86 (insert-file-contents file) | |
87 (goto-char (point-min)) | |
88 (while (not (eobp)) | |
89 (let* ((fields | |
90 (split-string (buffer-substring | |
91 (point) (progn (end-of-line) | |
92 (point))) ":"))) | |
93 (setq names (cons (nth 0 fields) names))) | |
94 (forward-line)))) | |
95 (pcomplete-uniqify-list names))) | |
96 | |
97 (defsubst pcmpl-unix-group-names () | |
98 "Read the contents of /etc/group for group names." | |
99 (if pcmpl-unix-group-file | |
100 (pcmpl-unix-read-passwd-file pcmpl-unix-group-file))) | |
101 | |
102 (defsubst pcmpl-unix-user-names () | |
103 "Read the contents of /etc/passwd for user names." | |
104 (if pcmpl-unix-passwd-file | |
105 (pcmpl-unix-read-passwd-file pcmpl-unix-passwd-file))) | |
106 | |
107 ;;;###autoload | |
108 (defun pcomplete/chown () | |
109 "Completion for the `chown' command." | |
110 (unless (pcomplete-match "\\`-") | |
111 (if (pcomplete-match "\\`[^.]*\\'" 0) | |
112 (pcomplete-here* (pcmpl-unix-user-names)) | |
113 (if (pcomplete-match "\\.\\([^.]*\\)\\'" 0) | |
114 (pcomplete-here* (pcmpl-unix-group-names) | |
115 (pcomplete-match-string 1 0)) | |
116 (pcomplete-here*)))) | |
117 (while (pcomplete-here (pcomplete-entries)))) | |
118 | |
119 ;;;###autoload | |
120 (defun pcomplete/chgrp () | |
121 "Completion for the `chgrp' command." | |
122 (unless (pcomplete-match "\\`-") | |
123 (pcomplete-here* (pcmpl-unix-group-names))) | |
124 (while (pcomplete-here (pcomplete-entries)))) | |
125 | |
52401 | 126 ;;; arch-tag: 3f9eb5af-7e0e-449d-b586-381cbbf8fc5c |
29959 | 127 ;;; pcmpl-unix.el ends here |