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: Pcompletion for ssh and scp Date: Tue, 04 Dec 2007 14:32:47 -0800 Message-ID: <85d4tmm6pc.fsf@evri.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1196807594 12441 80.91.229.12 (4 Dec 2007 22:33:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Dec 2007 22:33:14 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 04 23:33:22 2007 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.50) id 1IzgKI-0005kj-21 for ged-emacs-devel@m.gmane.org; Tue, 04 Dec 2007 23:33:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzgK1-0005RS-EO for ged-emacs-devel@m.gmane.org; Tue, 04 Dec 2007 17:32:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IzgJw-0005O6-JQ for emacs-devel@gnu.org; Tue, 04 Dec 2007 17:32:52 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IzgJu-0005Lu-KN for emacs-devel@gnu.org; Tue, 04 Dec 2007 17:32:51 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IzgJu-0005LR-Dj for emacs-devel@gnu.org; Tue, 04 Dec 2007 17:32:50 -0500 Original-Received: from sd-green-bigip-202.dreamhost.com ([208.97.132.202] helo=spunkymail-a10.g.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IzgJt-0004Pz-Om for emacs-devel@gnu.org; Tue, 04 Dec 2007 17:32:50 -0500 Original-Received: from imp (dsl081-164-013.sea1.dsl.speakeasy.net [64.81.164.13]) by spunkymail-a10.g.dreamhost.com (Postfix) with ESMTP id 80D591631AE for ; Tue, 4 Dec 2007 14:32:48 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:84680 Archived-At: --=-=-= Hello. I've added support for hostname completion in eshell when using ssh and scp. It gathers a list of hostnames from the ~/.ssh/known_hosts file. SSH completion completes only from the list of hostnames; SCP completes from files and directories currently present plus the list of hostnames. It also assumes that each hostname is followed by either a space or a comma, which is the case on the systems I've checked but may not be a universal rule. Would this be suitable for inclusion in Emacs? It may not be portable to all the systems Emacs supports since it assumes the existence of the known_hosts file, but I think it's fairly useful nonetheless. I've attached the file; please comment. -Phil --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=pcmpl-ssh.el Content-Transfer-Encoding: quoted-printable Content-Description: pcomplete support for ssh and scp ;;; pcmpl-ssh.el --- functions for completing SSH hostnames ;; Copyright (C) 2007 Phil Hagelberg ;; Author: Phil Hagelberg ;; URL: http://www.emacswiki.org/cgi-bin/wiki/pcmpl-ssh.el ;; Version: 0.2 ;; Created: 2007-12-02 ;; Keywords: shell completion ssh ;; EmacsWiki: PcompleteSSH ;; This file is NOT part of GNU Emacs. ;; Last-Updated: Sun Dec 04 11:51:06 2007 PST ;; By: Phil Hagelberg ;; Update #: 2 ;;; License: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This will allow eshell to autocomplete SSH hosts from the list of ;; known hosts in your ~/.ssh/known_hosts file. Note that newer ;; versions of ssh hash the hosts by default to prevent Island-hopping ;; SSH attacks. (https://itso.iu.edu/Hashing_the_OpenSSH_known__hosts_File) ;; You can disable this by putting the following line in your ~/.ssh/config ;; file following the "Host *" directive: ;; HashKnownHosts no ;; Note that this will make you vulnerable to the Island-hopping ;; attack described in the link above if you allow key-based ;; passwordless logins and your account is compromised. ;;; Code: (require 'pcomplete) (require 'executable) ;;;###autoload (defun pcomplete/ssh () "Completion rules for the `ssh' command." (pcomplete-opt "1246AaCfgKkMNnqsTtVvXxYbcDeFiLlmOopRSw" nil t) (pcomplete-here (pcmpl-ssh-hosts))) ;;;###autoload (defun pcomplete/scp () "Completion rules for the `scp' command. Includes files as well as host names followed by a colon." (pcomplete-opt "1246BCpqrvcFiloPS") (while t (pcomplete-here (append (pcomplete-all-entries) (mapcar (lambda (host) (concat host ":")= ) (pcmpl-ssh-hosts)))))) (defun pcmpl-ssh-hosts () "Returns a list of hosts found in the users `known_hosts' file." (if (file-readable-p "~/.ssh/known_hosts") (with-temp-buffer (insert-file-contents-literally "~/.ssh/known_hosts") (let ((ssh-hosts-list) '()) (while (not (eobp)) (add-to-list 'ssh-hosts-list (buffer-substring (point) (- (search-forward-regex= p "[, ]") 1))) (forward-line)) ssh-hosts-list)))) (provide 'pcmpl-ssh) ;;; pcmpl-ssh.el ends here --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--