* [PATCH] Improved SSH host support for pcomplete/eshell
@ 2010-12-29 20:10 Phil Hagelberg
2010-12-30 3:26 ` Chong Yidong
0 siblings, 1 reply; 3+ messages in thread
From: Phil Hagelberg @ 2010-12-29 20:10 UTC (permalink / raw)
To: Emacs discussions
I've added support to pcmpl-ssh-hosts for it to parse ~/.ssh/config
as well instead of just ~/.ssh/known_hosts.
Changelog entry:
2010-12-29 Phil Hagelberg <phil@hagelb.org>
* pcmpl-unix.el (pcmpl-ssh-config-file): New defcustom.
(pcmpl-ssh-hosts): Parse pcmpl-ssh-config-file in addition to
pcmpl-ssh-known-hosts-file.
(pcmpl-ssh-known-hosts, pcmpl-ssh-config-hosts): New functions.
I have already submitted copyright paperwork for a previous patch.
Comments?
-Phil
diff --git a/lisp/pcmpl-unix.el b/lisp/pcmpl-unix.el
index f2c19ca..f6b37b8 100644
--- a/lisp/pcmpl-unix.el
+++ b/lisp/pcmpl-unix.el
@@ -40,14 +40,21 @@
(defcustom pcmpl-ssh-known-hosts-file "~/.ssh/known_hosts"
"If non-nil, a string naming your SSH \"known_hosts\" file.
-This allows completion of SSH host names. Note that newer
-versions of ssh hash the hosts by default to prevent
+This allows one method of completion of SSH host names. Note
+that newer versions of ssh hash the hosts by default to prevent
Island-hopping SSH attacks. This can be disabled, at some risk,
with the SSH option \"HashKnownHosts no\"."
:type '(choice file (const nil))
:group 'pcmpl-unix
:version "23.1")
+(defcustom pcmpl-ssh-config-file "~/.ssh/config"
+ "If non-nil, a string naming your SSH \"config\" file.
+This allows one method of completion of SSH host names."
+ :type '(choice file (const nil))
+ :group 'pcmpl-unix
+ :version "24.1")
+
;; Functions:
;;;###autoload
@@ -138,7 +145,7 @@ documentation), this function returns nil."
;; ssh support by Phil Hagelberg.
;; http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el
-(defun pcmpl-ssh-hosts ()
+(defun pcmpl-ssh-known-hosts ()
"Return a list of hosts found in `pcmpl-ssh-known-hosts-file'."
(when (and pcmpl-ssh-known-hosts-file
(file-readable-p pcmpl-ssh-known-hosts-file))
@@ -153,6 +160,27 @@ documentation), this function returns nil."
(add-to-list 'ssh-hosts-list (match-string 1))))
ssh-hosts-list))))
+(defun pcmpl-ssh-config-hosts ()
+ "Return a list of hosts found in `pcmpl-ssh-config-file'."
+ (when (and pcmpl-ssh-config-file
+ (file-readable-p pcmpl-ssh-config-file))
+ (with-temp-buffer
+ (insert-file-contents-literally pcmpl-ssh-config-file)
+ (let (ssh-hosts-list
+ (case-fold-search t))
+ (while (re-search-forward "^ *host\\(name\\)? +\\([-.[:alnum:]]+\\)"
+ nil t)
+ (add-to-list 'ssh-hosts-list (match-string 2)))
+ ssh-hosts-list))))
+
+(defun pcmpl-ssh-hosts ()
+ "Return a list of known SSH hosts.
+Uses both `pcmpl-ssh-config-file' and `pcmpl-ssh-known-hosts-file'."
+ (let ((hosts (pcmpl-ssh-known-hosts)))
+ (dolist (h (pcmpl-ssh-config-hosts))
+ (add-to-list 'hosts h))
+ hosts))
+
;;;###autoload
(defun pcomplete/ssh ()
"Completion rules for the `ssh' command."
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Improved SSH host support for pcomplete/eshell
2010-12-29 20:10 [PATCH] Improved SSH host support for pcomplete/eshell Phil Hagelberg
@ 2010-12-30 3:26 ` Chong Yidong
2010-12-30 17:44 ` Phil Hagelberg
0 siblings, 1 reply; 3+ messages in thread
From: Chong Yidong @ 2010-12-30 3:26 UTC (permalink / raw)
To: Phil Hagelberg; +Cc: Emacs discussions
Phil Hagelberg <phil@hagelb.org> writes:
> I've added support to pcmpl-ssh-hosts for it to parse ~/.ssh/config
> as well instead of just ~/.ssh/known_hosts.
Thanks. If I understand correctly, this is only used to get ssh host
aliases, right? You should probably make a note of this improvement in
NEWS.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Improved SSH host support for pcomplete/eshell
2010-12-30 3:26 ` Chong Yidong
@ 2010-12-30 17:44 ` Phil Hagelberg
0 siblings, 0 replies; 3+ messages in thread
From: Phil Hagelberg @ 2010-12-30 17:44 UTC (permalink / raw)
To: Chong Yidong; +Cc: Emacs discussions
On Wed, Dec 29, 2010 at 7:26 PM, Chong Yidong <cyd@stupidchicken.com> wrote:
> Phil Hagelberg <phil@hagelb.org> writes:
>> I've added support to pcmpl-ssh-hosts for it to parse ~/.ssh/config
>> as well instead of just ~/.ssh/known_hosts.
>
> Thanks. If I understand correctly, this is only used to get ssh host
> aliases, right? You should probably make a note of this improvement in
> NEWS.
That's correct. Here's an updated version of the patch that adds an entry to
NEWS and clarifies some of the docstrings.
-Phil
diff --git a/etc/NEWS b/etc/NEWS
index f21028a..b84ae9d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -344,6 +344,9 @@ utf-8, and do the normal `undecided' decoding for the rest.
** Eshell changes
+*** Tab completion for SSH hosts now additionally uses hostname
+aliases from ~/.ssh/config rather than just known_hosts key entries.
+
*** The default value of eshell-directory-name is a directory named
"eshell" in `user-emacs-directory'. If the old "~/.eshell/" directory
exists, that is used instead.
diff --git a/lisp/pcmpl-unix.el b/lisp/pcmpl-unix.el
index f2c19ca..ff3d8e7 100644
--- a/lisp/pcmpl-unix.el
+++ b/lisp/pcmpl-unix.el
@@ -40,14 +40,21 @@
(defcustom pcmpl-ssh-known-hosts-file "~/.ssh/known_hosts"
"If non-nil, a string naming your SSH \"known_hosts\" file.
-This allows completion of SSH host names. Note that newer
-versions of ssh hash the hosts by default to prevent
-Island-hopping SSH attacks. This can be disabled, at some risk,
-with the SSH option \"HashKnownHosts no\"."
+This allows completion of SSH host names based on saved host
+keys. Note that newer versions of ssh hash the hosts by default
+to prevent Island-hopping SSH attacks. This can be disabled, at
+some risk, with the SSH option \"HashKnownHosts no\"."
:type '(choice file (const nil))
:group 'pcmpl-unix
:version "23.1")
+(defcustom pcmpl-ssh-config-file "~/.ssh/config"
+ "If non-nil, a string naming your SSH \"config\" file.
+This allows completion of SSH host names based on configured aliases."
+ :type '(choice file (const nil))
+ :group 'pcmpl-unix
+ :version "24.1")
+
;; Functions:
;;;###autoload
@@ -138,7 +145,7 @@ documentation), this function returns nil."
;; ssh support by Phil Hagelberg.
;; http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el
-(defun pcmpl-ssh-hosts ()
+(defun pcmpl-ssh-known-hosts ()
"Return a list of hosts found in `pcmpl-ssh-known-hosts-file'."
(when (and pcmpl-ssh-known-hosts-file
(file-readable-p pcmpl-ssh-known-hosts-file))
@@ -153,6 +160,27 @@ documentation), this function returns nil."
(add-to-list 'ssh-hosts-list (match-string 1))))
ssh-hosts-list))))
+(defun pcmpl-ssh-config-hosts ()
+ "Return a list of host aliases found in `pcmpl-ssh-config-file'."
+ (when (and pcmpl-ssh-config-file
+ (file-readable-p pcmpl-ssh-config-file))
+ (with-temp-buffer
+ (insert-file-contents-literally pcmpl-ssh-config-file)
+ (let (ssh-hosts-list
+ (case-fold-search t))
+ (while (re-search-forward "^ *host\\(name\\)? +\\([-.[:alnum:]]+\\)"
+ nil t)
+ (add-to-list 'ssh-hosts-list (match-string 2)))
+ ssh-hosts-list))))
+
+(defun pcmpl-ssh-hosts ()
+ "Return a list of known SSH hosts.
+Uses both `pcmpl-ssh-config-file' and `pcmpl-ssh-known-hosts-file'."
+ (let ((hosts (pcmpl-ssh-known-hosts)))
+ (dolist (h (pcmpl-ssh-config-hosts))
+ (add-to-list 'hosts h))
+ hosts))
+
;;;###autoload
(defun pcomplete/ssh ()
"Completion rules for the `ssh' command."
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-30 17:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-29 20:10 [PATCH] Improved SSH host support for pcomplete/eshell Phil Hagelberg
2010-12-30 3:26 ` Chong Yidong
2010-12-30 17:44 ` Phil Hagelberg
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).