From 21c7e9e6c0a662a05a70e50309814ed16292a498 Mon Sep 17 00:00:00 2001 From: Dante Catalfamo Date: Thu, 26 Nov 2020 16:29:24 -0500 Subject: ox-ssh: add bonus elisp --- content/posts/org-ssh-export/index.org | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'content') diff --git a/content/posts/org-ssh-export/index.org b/content/posts/org-ssh-export/index.org index f9faaad..bf6ae0c 100644 --- a/content/posts/org-ssh-export/index.org +++ b/content/posts/org-ssh-export/index.org @@ -161,3 +161,34 @@ to bring up the org export dispatch, then @@html: s@@ to select =Export to SSH config=, and @@html: x@@ to overwrite my existing ssh config file with the newly generated one. + +*BONUS* + +On reddit, user =Funkmaster_Lincoln= [[https://www.reddit.com/r/emacs/comments/k1hfgo/how_i_keep_track_of_my_servers/gdow00y/?context=3][mentioned]] in response to this +post that it would be interesting if one could press a key on the +server heading to connect, without having to add the server to one's +SSH configuration. I had a go at trying to write out what that might +look like, and this is what I came up with. + +#+begin_src emacs-lisp +(defun org-ssh-connect (&optional arg) + "Connect to the host at point and open `dired'. +If ARG is non-nil, open `eshell' instead of `dired'." + (interactive "P") + (let* ((properties (org-entry-properties)) + (name (alist-get "ITEM" properties nil nil #'string=)) + (user (alist-get "SSH_USER" properties nil nil #'string=)) + (port (alist-get "SSH_PORT" properties nil nil #'string=)) + (host (or (alist-get "IP" properties nil nil #'string=) + (alist-get "HOSTNAME" properties nil nil #'string=)))) + (if host + (let ((default-directory (format "/ssh:%s%s%s:" + (if user (format "%s@" user) "") + name + (if port (format "#%s" port) "")))) + (message "Connecting to %s..." name) + (if arg + (eshell t) + (dired "."))) + (user-error "Not an SSH host")))) +#+end_src -- cgit v1.2.3