1 ;;; pcmpl-unix.el --- 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., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
32 (defcustom pcmpl-unix-group-file
"/etc/group"
33 "*If non-nil, a string naming the group file on your system."
37 (defcustom pcmpl-unix-passwd-file
"/etc/passwd"
38 "*If non-nil, a string naming the passwd file on your system."
45 (defun pcomplete/cd
()
46 "Completion for `cd'."
47 (pcomplete-here (pcomplete-dirs)))
50 (defalias 'pcomplete
/pushd
'pcomplete
/cd
)
53 (defun pcomplete/rmdir
()
54 "Completion for `rmdir'."
55 (while (pcomplete-here (pcomplete-dirs))))
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
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
)))
73 (defalias 'pcomplete
/time
'pcomplete
/xargs
)
76 (defun pcomplete/which
()
77 "Completion for `which'."
78 (while (pcomplete-here (funcall pcomplete-command-completion-function
))))
80 (defun pcmpl-unix-read-passwd-file (file)
81 "Return an alist correlating gids to group names in FILE."
83 (when (file-readable-p file
)
85 (insert-file-contents file
)
86 (goto-char (point-min))
89 (split-string (buffer-substring
90 (point) (progn (end-of-line)
92 (setq names
(cons (nth 0 fields
) names
)))
94 (pcomplete-uniqify-list names
)))
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
)))
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
)))
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))
116 (while (pcomplete-here (pcomplete-entries))))
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))))
125 ;;; arch-tag: 3f9eb5af-7e0e-449d-b586-381cbbf8fc5c
126 ;;; pcmpl-unix.el ends here