(x_set_glyph_string_background_width): Set the glyph
[emacs.git] / lisp / pcmpl-unix.el
blobe4ed4cbf16b50ff4aff333327bfbdef9808b1af7
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)
10 ;; any later version.
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.
22 ;;; Commentary:
24 ;;; Code:
26 (provide 'pcmpl-unix)
28 (require 'pcomplete)
30 ;; User Variables:
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)
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)
42 ;; Functions:
44 ;;;###autoload
45 (defun pcomplete/cd ()
46 "Completion for `cd'."
47 (pcomplete-here (pcomplete-dirs)))
49 ;;;###autoload
50 (defalias 'pcomplete/pushd 'pcomplete/cd)
52 ;;;###autoload
53 (defun pcomplete/rmdir ()
54 "Completion for `rmdir'."
55 (while (pcomplete-here (pcomplete-dirs))))
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))))
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)))
72 ;;;###autoload
73 (defalias 'pcomplete/time 'pcomplete/xargs)
75 ;;;###autoload
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."
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)))
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)))
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))))
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))))
125 ;;; pcmpl-unix.el ends here