summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/posts/org-ssh-export/index.org31
1 files changed, 31 insertions, 0 deletions
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: <kbd>s</kbd>@@ to select =Export to SSH config=, and
@@html: <kbd>x</kbd>@@ 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