Skip to content

Commit

Permalink
Add support for top-level sshconfig include
Browse files Browse the repository at this point in the history
  • Loading branch information
masasam committed Jan 25, 2019
1 parent 2351956 commit ac7728b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions counsel-tramp.el
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit ac7728b

Please sign in to comment.