Mercurial > emacs
annotate lisp/pcmpl-unix.el @ 93429:ca8fb3f3e855
* net/trampver.el: Update release number.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Sun, 30 Mar 2008 18:03:25 +0000 |
parents | 681a1b7488c2 |
children | ee5932bf781d |
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, |
79721 | 4 ;; 2005, 2006, 2007, 2008 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 | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
10 ;; the Free Software Foundation; either version 3, or (at your option) |
29959 | 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 (require 'pcomplete) | |
28 | |
29 ;; User Variables: | |
30 | |
31 (defcustom pcmpl-unix-group-file "/etc/group" | |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
32 "If non-nil, a string naming the group file on your system." |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
33 :type '(choice file (const nil)) |
29959 | 34 :group 'pcmpl-unix) |
35 | |
36 (defcustom pcmpl-unix-passwd-file "/etc/passwd" | |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
37 "If non-nil, a string naming the passwd file on your system." |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
38 :type '(choice file (const nil)) |
29959 | 39 :group 'pcmpl-unix) |
40 | |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
41 (defcustom pcmpl-ssh-known-hosts-file "~/.ssh/known_hosts" |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
42 "If non-nil, a string naming your SSH \"known_hosts\" file. |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
43 This allows completion of SSH host names. Note that newer |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
44 versions of ssh hash the hosts by default to prevent |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
45 Island-hopping SSH attacks. This can be disabled, at some risk, |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
46 with the SSH option \"HashKnownHosts no\"." |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
47 :type '(choice file (const nil)) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
48 :group 'pcmpl-unix |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
49 :version "23.1") |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
50 |
29959 | 51 ;; Functions: |
52 | |
53 ;;;###autoload | |
54 (defun pcomplete/cd () | |
55 "Completion for `cd'." | |
56 (pcomplete-here (pcomplete-dirs))) | |
57 | |
58 ;;;###autoload | |
59 (defalias 'pcomplete/pushd 'pcomplete/cd) | |
60 | |
61 ;;;###autoload | |
62 (defun pcomplete/rmdir () | |
63 "Completion for `rmdir'." | |
64 (while (pcomplete-here (pcomplete-dirs)))) | |
65 | |
66 ;;;###autoload | |
67 (defun pcomplete/rm () | |
68 "Completion for `rm'." | |
69 (let ((pcomplete-help "(fileutils)rm invocation")) | |
70 (pcomplete-opt "dfirRv") | |
71 (while (pcomplete-here (pcomplete-all-entries) nil | |
72 'expand-file-name)))) | |
73 | |
74 ;;;###autoload | |
75 (defun pcomplete/xargs () | |
76 "Completion for `xargs'." | |
77 (pcomplete-here (funcall pcomplete-command-completion-function)) | |
78 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
79 pcomplete-default-completion-function))) | |
80 | |
81 ;;;###autoload | |
82 (defalias 'pcomplete/time 'pcomplete/xargs) | |
83 | |
84 ;;;###autoload | |
85 (defun pcomplete/which () | |
86 "Completion for `which'." | |
87 (while (pcomplete-here (funcall pcomplete-command-completion-function)))) | |
88 | |
89 (defun pcmpl-unix-read-passwd-file (file) | |
90 "Return an alist correlating gids to group names in FILE." | |
91 (let (names) | |
92 (when (file-readable-p file) | |
93 (with-temp-buffer | |
94 (insert-file-contents file) | |
95 (goto-char (point-min)) | |
96 (while (not (eobp)) | |
97 (let* ((fields | |
98 (split-string (buffer-substring | |
99 (point) (progn (end-of-line) | |
100 (point))) ":"))) | |
101 (setq names (cons (nth 0 fields) names))) | |
102 (forward-line)))) | |
103 (pcomplete-uniqify-list names))) | |
104 | |
105 (defsubst pcmpl-unix-group-names () | |
106 "Read the contents of /etc/group for group names." | |
107 (if pcmpl-unix-group-file | |
108 (pcmpl-unix-read-passwd-file pcmpl-unix-group-file))) | |
109 | |
110 (defsubst pcmpl-unix-user-names () | |
111 "Read the contents of /etc/passwd for user names." | |
112 (if pcmpl-unix-passwd-file | |
113 (pcmpl-unix-read-passwd-file pcmpl-unix-passwd-file))) | |
114 | |
115 ;;;###autoload | |
116 (defun pcomplete/chown () | |
117 "Completion for the `chown' command." | |
118 (unless (pcomplete-match "\\`-") | |
119 (if (pcomplete-match "\\`[^.]*\\'" 0) | |
120 (pcomplete-here* (pcmpl-unix-user-names)) | |
121 (if (pcomplete-match "\\.\\([^.]*\\)\\'" 0) | |
122 (pcomplete-here* (pcmpl-unix-group-names) | |
123 (pcomplete-match-string 1 0)) | |
124 (pcomplete-here*)))) | |
125 (while (pcomplete-here (pcomplete-entries)))) | |
126 | |
127 ;;;###autoload | |
128 (defun pcomplete/chgrp () | |
129 "Completion for the `chgrp' command." | |
130 (unless (pcomplete-match "\\`-") | |
131 (pcomplete-here* (pcmpl-unix-group-names))) | |
132 (while (pcomplete-here (pcomplete-entries)))) | |
133 | |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
134 |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
135 ;; ssh support by Phil Hagelberg. |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
136 ;; http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
137 |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
138 (defun pcmpl-ssh-hosts () |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
139 "Return a list of hosts found in `pcmpl-ssh-known-hosts-file'." |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
140 (when (and pcmpl-ssh-known-hosts-file |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
141 (file-readable-p pcmpl-ssh-known-hosts-file)) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
142 (with-temp-buffer |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
143 (insert-file-contents-literally pcmpl-ssh-known-hosts-file) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
144 (let (ssh-hosts-list) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
145 (while (re-search-forward "^ *\\([-.[:alnum:]]+\\)[, ]" nil t) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
146 (add-to-list 'ssh-hosts-list (match-string 1)) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
147 (while (and (looking-back ",") |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
148 (re-search-forward "\\([-.[:alnum:]]+\\)[, ]" |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
149 (line-end-position) t)) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
150 (add-to-list 'ssh-hosts-list (match-string 1)))) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
151 ssh-hosts-list)))) |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
152 |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
153 ;;;###autoload |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
154 (defun pcomplete/ssh () |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
155 "Completion rules for the `ssh' command." |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
156 (pcomplete-opt "1246AaCfgKkMNnqsTtVvXxYbcDeFiLlmOopRSw" nil t) |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
157 (pcomplete-here (pcmpl-ssh-hosts))) |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
158 |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
159 ;;;###autoload |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
160 (defun pcomplete/scp () |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
161 "Completion rules for the `scp' command. |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
162 Includes files as well as host names followed by a colon." |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
163 (pcomplete-opt "1246BCpqrvcFiloPS") |
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
164 (while t (pcomplete-here (append (pcomplete-all-entries) |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
165 (mapcar (lambda (host) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
166 (concat host ":")) |
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
167 (pcmpl-ssh-hosts)))))) |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
168 |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
169 (provide 'pcmpl-unix) |
91643
d3922949ea68
Phil Hagelberg <phil at evri.com>
Glenn Morris <rgm@gnu.org>
parents:
79721
diff
changeset
|
170 |
91644
681a1b7488c2
(top-level): Move provide statement to end.
Glenn Morris <rgm@gnu.org>
parents:
91643
diff
changeset
|
171 ;; arch-tag: 3f9eb5af-7e0e-449d-b586-381cbbf8fc5c |
29959 | 172 ;;; pcmpl-unix.el ends here |