From ac7728bac51afdcb63cd85ad22a8be5737d9d66f Mon Sep 17 00:00:00 2001 From: Masashi Miyaura Date: Fri, 25 Jan 2019 16:51:43 +0900 Subject: [PATCH] Add support for top-level sshconfig include --- counsel-tramp.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/counsel-tramp.el b/counsel-tramp.el index d1ce8ff..51d37d7 100644 --- a/counsel-tramp.el +++ b/counsel-tramp.el @@ -1,10 +1,10 @@ ;;; counsel-tramp.el --- Tramp ivy interface for ssh, docker, vagrant -*- lexical-binding: t; -*- -;; Copyright (C) 2017-2018 by Masashı Mıyaura +;; Copyright (C) 2017-2019 by Masashı Mıyaura ;; Author: Masashı Mıyaura ;; URL: https://github.com/masasam/emacs-counsel-tramp -;; Version: 0.5.2 +;; Version: 0.6.2 ;; Package-Requires: ((emacs "24.3") (counsel "0.10")) ;; This program is free software; you can redistribute it and/or modify @@ -74,14 +74,14 @@ Kill all remote buffers." (run-hooks 'counsel-tramp-quit-hook) (tramp-cleanup-all-buffers)) -(defun counsel-tramp--candidates () - "Collect candidates for counsel-tramp." +(defun counsel-tramp--candidates (&optional file) + "Collect candidates for counsel-tramp from FILE." (let ((source (split-string (with-temp-buffer - (insert-file-contents "~/.ssh/config") + (insert-file-contents (or file "~/.ssh/config")) (buffer-string)) "\n")) - (hosts counsel-tramp-custom-connections)) + (hosts (if file '() counsel-tramp-custom-connections))) (dolist (host source) (when (string-match "[H\\|h]ost +\\(.+?\\)$" host) (setq host (match-string 1 host)) @@ -105,7 +105,13 @@ Kill all remote buffers." hosts) (push (concat "/ssh:" host "|sudo:root@" host ":/") - hosts))))) + hosts)))) + (when (string-match "Include +\\(.+\\)$" host) + (setq include-file (match-string 1 host)) + (when (not (file-name-absolute-p include-file)) + (setq include-file (concat (file-name-as-directory "~/.ssh") include-file))) + (when (file-exists-p include-file) + (setq hosts (append hosts (counsel-tramp--candidates include-file)))))) (when (require 'docker-tramp nil t) (cl-loop for line in (cdr (ignore-errors (apply #'process-lines "docker" (list "ps")))) for info = (reverse (split-string line "[[:space:]]+" t))