Mercurial > emacs
comparison lisp/pcmpl-unix.el @ 112405:c04fdfa95f79
Add pcomplete support for hosts defined in .ssh/config.
* lisp/pcmpl-unix.el (pcmpl-ssh-config-file): New option.
(pcmpl-ssh-known-hosts): Rename from pcmpl-ssh-hosts.
(pcmpl-ssh-config-hosts): New function.
(pcmpl-ssh-hosts): Use pcmpl-ssh-config-hosts in addition to
pcmpl-ssh-known-hosts.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Fri, 21 Jan 2011 21:20:57 -0500 |
parents | ef719132ddfa |
children |
comparison
equal
deleted
inserted
replaced
112404:2b0d6f7bbb80 | 112405:c04fdfa95f79 |
---|---|
38 :type '(choice file (const nil)) | 38 :type '(choice file (const nil)) |
39 :group 'pcmpl-unix) | 39 :group 'pcmpl-unix) |
40 | 40 |
41 (defcustom pcmpl-ssh-known-hosts-file "~/.ssh/known_hosts" | 41 (defcustom pcmpl-ssh-known-hosts-file "~/.ssh/known_hosts" |
42 "If non-nil, a string naming your SSH \"known_hosts\" file. | 42 "If non-nil, a string naming your SSH \"known_hosts\" file. |
43 This allows completion of SSH host names. Note that newer | 43 This allows one method of completion of SSH host names, the other |
44 versions of ssh hash the hosts by default to prevent | 44 being via `pcmpl-ssh-config-file'. Note that newer versions of |
45 Island-hopping SSH attacks. This can be disabled, at some risk, | 45 ssh hash the hosts by default, to prevent Island-hopping SSH |
46 with the SSH option \"HashKnownHosts no\"." | 46 attacks. This can be disabled, at some risk, with the SSH option |
47 \"HashKnownHosts no\"." | |
47 :type '(choice file (const nil)) | 48 :type '(choice file (const nil)) |
48 :group 'pcmpl-unix | 49 :group 'pcmpl-unix |
49 :version "23.1") | 50 :version "23.1") |
51 | |
52 (defcustom pcmpl-ssh-config-file "~/.ssh/config" | |
53 "If non-nil, a string naming your SSH \"config\" file. | |
54 This allows one method of completion of SSH host names, the other | |
55 being via `pcmpl-ssh-known-hosts-file'." | |
56 :type '(choice file (const nil)) | |
57 :group 'pcmpl-unix | |
58 :version "24.1") | |
50 | 59 |
51 ;; Functions: | 60 ;; Functions: |
52 | 61 |
53 ;;;###autoload | 62 ;;;###autoload |
54 (defun pcomplete/cd () | 63 (defun pcomplete/cd () |
136 | 145 |
137 | 146 |
138 ;; ssh support by Phil Hagelberg. | 147 ;; ssh support by Phil Hagelberg. |
139 ;; http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el | 148 ;; http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el |
140 | 149 |
141 (defun pcmpl-ssh-hosts () | 150 (defun pcmpl-ssh-known-hosts () |
142 "Return a list of hosts found in `pcmpl-ssh-known-hosts-file'." | 151 "Return a list of hosts found in `pcmpl-ssh-known-hosts-file'." |
143 (when (and pcmpl-ssh-known-hosts-file | 152 (when (and pcmpl-ssh-known-hosts-file |
144 (file-readable-p pcmpl-ssh-known-hosts-file)) | 153 (file-readable-p pcmpl-ssh-known-hosts-file)) |
145 (with-temp-buffer | 154 (with-temp-buffer |
146 (insert-file-contents-literally pcmpl-ssh-known-hosts-file) | 155 (insert-file-contents-literally pcmpl-ssh-known-hosts-file) |
151 (re-search-forward "\\([-.[:alnum:]]+\\)[, ]" | 160 (re-search-forward "\\([-.[:alnum:]]+\\)[, ]" |
152 (line-end-position) t)) | 161 (line-end-position) t)) |
153 (add-to-list 'ssh-hosts-list (match-string 1)))) | 162 (add-to-list 'ssh-hosts-list (match-string 1)))) |
154 ssh-hosts-list)))) | 163 ssh-hosts-list)))) |
155 | 164 |
165 (defun pcmpl-ssh-config-hosts () | |
166 "Return a list of hosts found in `pcmpl-ssh-config-file'." | |
167 (when (and pcmpl-ssh-config-file | |
168 (file-readable-p pcmpl-ssh-config-file)) | |
169 (with-temp-buffer | |
170 (insert-file-contents-literally pcmpl-ssh-config-file) | |
171 (let (ssh-hosts-list | |
172 (case-fold-search t)) | |
173 (while (re-search-forward "^ *host\\(name\\)? +\\([-.[:alnum:]]+\\)" | |
174 nil t) | |
175 (add-to-list 'ssh-hosts-list (match-string 2))) | |
176 ssh-hosts-list)))) | |
177 | |
178 (defun pcmpl-ssh-hosts () | |
179 "Return a list of known SSH hosts. | |
180 Uses both `pcmpl-ssh-config-file' and `pcmpl-ssh-known-hosts-file'." | |
181 (let ((hosts (pcmpl-ssh-known-hosts))) | |
182 (dolist (h (pcmpl-ssh-config-hosts)) | |
183 (add-to-list 'hosts h)) | |
184 hosts)) | |
185 | |
156 ;;;###autoload | 186 ;;;###autoload |
157 (defun pcomplete/ssh () | 187 (defun pcomplete/ssh () |
158 "Completion rules for the `ssh' command." | 188 "Completion rules for the `ssh' command." |
159 (pcomplete-opt "1246AaCfgKkMNnqsTtVvXxYbcDeFiLlmOopRSw" nil t) | 189 (pcomplete-opt "1246AaCfgKkMNnqsTtVvXxYbcDeFiLlmOopRSw" nil t) |
160 (pcomplete-here (pcmpl-ssh-hosts))) | 190 (pcomplete-here (pcmpl-ssh-hosts))) |