Skip to content

Instantly share code, notes, and snippets.

@gempesaw
Last active December 12, 2015 04:28
Show Gist options
  • Select an option

  • Save gempesaw/4714693 to your computer and use it in GitHub Desktop.

Select an option

Save gempesaw/4714693 to your computer and use it in GitHub Desktop.
(setq ssh-config-path "~/.ssh/config")
(defun get-file-as-string (filePath)
"Return FILEPATH's file content."
(with-temp-buffer
(insert-file-contents filePath)
(split-string
(buffer-string) "\n" t)))
(defun get-remote-names ()
(interactive)
(let ((ssh-config (get-file-as-string ssh-config-path) )
(ssh-host-names))
(while ssh-config
(let ((line (car ssh-config)))
(if (and (string-match-p "Host " line)
(not (string-match-p "*" line))
(not (string-match-p "^# " line)))
(setq ssh-host-names (cons (cadr (split-string line " "))
ssh-host-names))))
(setq ssh-config (cdr ssh-config)))
ssh-host-names))
(defun open-ssh-connection (&optional pfx)
(interactive "p")
(let ((box (ido-completing-read "Which box: " (get-remote-names)))
(buffer "*ssh-"))
(setq buffer (concat buffer box "*"))
(save-window-excursion
(async-shell-command (concat "ssh " box)
(generate-new-buffer-name buffer)))
(if (eq pfx 4)
(progn
(split-window)
(other-window 1)))
(switch-to-buffer buffer)
(set-process-query-on-exit-flag (get-buffer-process buffer) nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment