1 ;;; pcmpl-unix --- standard UNIX 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.
30 (defcustom pcmpl-unix-group-file
"/etc/group"
31 "*If non-nil, a string naming the group file on your system."
35 (defcustom pcmpl-unix-passwd-file
"/etc/passwd"
36 "*If non-nil, a string naming the passwd file on your system."
43 (defun pcomplete/cd
()
44 "Completion for `cd'."
45 (pcomplete-here (pcomplete-dirs)))
48 (defalias 'pcomplete
/pushd
'pcomplete
/cd
)
51 (defun pcomplete/rmdir
()
52 "Completion for `rmdir'."
53 (while (pcomplete-here (pcomplete-dirs))))
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
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
)))
71 (defalias 'pcomplete
/time
'pcomplete
/xargs
)
74 (defun pcomplete/which
()
75 "Completion for `which'."
76 (while (pcomplete-here (funcall pcomplete-command-completion-function
))))
78 (defun pcmpl-unix-read-passwd-file (file)
79 "Return an alist correlating gids to group names in FILE."
81 (when (file-readable-p file
)
83 (insert-file-contents file
)
84 (goto-char (point-min))
87 (split-string (buffer-substring
88 (point) (progn (end-of-line)
90 (setq names
(cons (nth 0 fields
) names
)))
92 (pcomplete-uniqify-list names
)))
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
)))
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
)))
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))
114 (while (pcomplete-here (pcomplete-entries))))
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))))
123 ;;; pcmpl-unix.el ends here