1 ;;; pcmpl-unix.el --- standard UNIX completions
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
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)
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.
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
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
33 (defcustom pcmpl-unix-group-file
"/etc/group"
34 "*If non-nil, a string naming the group file on your system."
38 (defcustom pcmpl-unix-passwd-file
"/etc/passwd"
39 "*If non-nil, a string naming the passwd file on your system."
46 (defun pcomplete/cd
()
47 "Completion for `cd'."
48 (pcomplete-here (pcomplete-dirs)))
51 (defalias 'pcomplete
/pushd
'pcomplete
/cd
)
54 (defun pcomplete/rmdir
()
55 "Completion for `rmdir'."
56 (while (pcomplete-here (pcomplete-dirs))))
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
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
)))
74 (defalias 'pcomplete
/time
'pcomplete
/xargs
)
77 (defun pcomplete/which
()
78 "Completion for `which'."
79 (while (pcomplete-here (funcall pcomplete-command-completion-function
))))
81 (defun pcmpl-unix-read-passwd-file (file)
82 "Return an alist correlating gids to group names in FILE."
84 (when (file-readable-p file
)
86 (insert-file-contents file
)
87 (goto-char (point-min))
90 (split-string (buffer-substring
91 (point) (progn (end-of-line)
93 (setq names
(cons (nth 0 fields
) names
)))
95 (pcomplete-uniqify-list names
)))
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
)))
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
)))
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))
117 (while (pcomplete-here (pcomplete-entries))))
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))))
126 ;;; arch-tag: 3f9eb5af-7e0e-449d-b586-381cbbf8fc5c
127 ;;; pcmpl-unix.el ends here