From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Phil Hagelberg Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Improved SSH host support for pcomplete/eshell Date: Thu, 30 Dec 2010 09:44:51 -0800 Message-ID: References: <87d3okgcv0.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1293731115 10874 80.91.229.12 (30 Dec 2010 17:45:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 30 Dec 2010 17:45:15 +0000 (UTC) Cc: Emacs discussions To: Chong Yidong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 30 18:45:11 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PYMYo-0005f4-Pm for ged-emacs-devel@m.gmane.org; Thu, 30 Dec 2010 18:45:11 +0100 Original-Received: from localhost ([127.0.0.1]:59284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PYMYn-0003v9-Vt for ged-emacs-devel@m.gmane.org; Thu, 30 Dec 2010 12:45:10 -0500 Original-Received: from [140.186.70.92] (port=54420 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PYMYb-0003rf-9u for emacs-devel@gnu.org; Thu, 30 Dec 2010 12:45:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PYMYW-0002g6-DY for emacs-devel@gnu.org; Thu, 30 Dec 2010 12:44:57 -0500 Original-Received: from mail-gx0-f169.google.com ([209.85.161.169]:44384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PYMYW-0002fh-9W for emacs-devel@gnu.org; Thu, 30 Dec 2010 12:44:52 -0500 Original-Received: by gxk5 with SMTP id 5so5458614gxk.0 for ; Thu, 30 Dec 2010 09:44:51 -0800 (PST) Original-Received: by 10.100.136.14 with SMTP id j14mr4696942and.262.1293731091452; Thu, 30 Dec 2010 09:44:51 -0800 (PST) Original-Received: by 10.100.57.18 with HTTP; Thu, 30 Dec 2010 09:44:51 -0800 (PST) In-Reply-To: <87d3okgcv0.fsf@stupidchicken.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:134055 Archived-At: On Wed, Dec 29, 2010 at 7:26 PM, Chong Yidong wrote= : > Phil Hagelberg writes: >> I've added support to pcmpl-ssh-hosts for it to parse ~/.ssh/config >> as well instead of just ~/.ssh/known_hosts. > > Thanks. =C2=A0If I understand correctly, this is only used to get ssh hos= t > aliases, right? =C2=A0You 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 t= o 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 r= est. ** 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."