aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Hagelberg2011-01-21 21:20:57 -0500
committerChong Yidong2011-01-21 21:20:57 -0500
commit6b072b27ee12c944142e310c984df028118713da (patch)
treee4fa961a5bbca97afadc23e9edb9fcdb3305905f
parent7d77be379f282812eec91436b174d3d00c010cb5 (diff)
downloademacs-6b072b27ee12c944142e310c984df028118713da.tar.gz
emacs-6b072b27ee12c944142e310c984df028118713da.zip
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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/pcmpl-unix.el40
2 files changed, 43 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cf51ddc109a..22fee77f584 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12011-01-22 Phil Hagelberg <phil@evri.com>
2
3 * pcmpl-unix.el (pcmpl-ssh-config-file): New option.
4 (pcmpl-ssh-known-hosts): Rename from pcmpl-ssh-hosts.
5 (pcmpl-ssh-config-hosts): New function.
6 (pcmpl-ssh-hosts): Use pcmpl-ssh-config-hosts in addition to
7 pcmpl-ssh-known-hosts.
8
12011-01-21 Jay Belanger <jay.p.belanger@gmail.com> 92011-01-21 Jay Belanger <jay.p.belanger@gmail.com>
2 10
3 * calc/calc-undo.el (calc-undo): Autoload it. 11 * calc/calc-undo.el (calc-undo): Autoload it.
diff --git a/lisp/pcmpl-unix.el b/lisp/pcmpl-unix.el
index 9b3857842fe..bbeb615d5b7 100644
--- a/lisp/pcmpl-unix.el
+++ b/lisp/pcmpl-unix.el
@@ -40,14 +40,23 @@
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.
43This allows completion of SSH host names. Note that newer 43This allows one method of completion of SSH host names, the other
44versions of ssh hash the hosts by default to prevent 44being via `pcmpl-ssh-config-file'. Note that newer versions of
45Island-hopping SSH attacks. This can be disabled, at some risk, 45ssh hash the hosts by default, to prevent Island-hopping SSH
46with the SSH option \"HashKnownHosts no\"." 46attacks. 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")
50 51
52(defcustom pcmpl-ssh-config-file "~/.ssh/config"
53 "If non-nil, a string naming your SSH \"config\" file.
54This allows one method of completion of SSH host names, the other
55being via `pcmpl-ssh-known-hosts-file'."
56 :type '(choice file (const nil))
57 :group 'pcmpl-unix
58 :version "24.1")
59
51;; Functions: 60;; Functions:
52 61
53;;;###autoload 62;;;###autoload
@@ -138,7 +147,7 @@ documentation), this function returns nil."
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))
@@ -153,6 +162,27 @@ documentation), this function returns nil."
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.
180Uses 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."