about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-20T23·18+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-20T23·18+0000
commit1fbc80359b88bad34bd2f11300cc2855f4c8527f (patch)
treee439d3da8d70d94ca18d5f46fe3c92b7bba72e0e
parent79013316a600cec7ef89ba0c077f2bec16dbee0d (diff)
Support ssh/{sudo-buffer,cd-home}
- Support command to open a dired buffer with wpcarro's $HOME directory for any
  host defined in ssh/hosts.
- Support opening the current buffer with sudo privileges.
-rw-r--r--emacs/.emacs.d/wpc/ssh.el20
1 files changed, 17 insertions, 3 deletions
diff --git a/emacs/.emacs.d/wpc/ssh.el b/emacs/.emacs.d/wpc/ssh.el
index 3e30e39bb801..c988c96d63fd 100644
--- a/emacs/.emacs.d/wpc/ssh.el
+++ b/emacs/.emacs.d/wpc/ssh.el
@@ -33,10 +33,24 @@
 ;; Maximizes the tramp debugging noisiness while I'm still learning about tramp.
 (setq tramp-verbose 10)
 
-(defun ssh/desktop-cd-home ()
-  "Open a dired buffer of my desktop's home directory for wpcarro."
+(defcustom ssh/hosts '("desktop" "flattop")
+  "List of hosts to which I commonly connect.
+Note: It could be interesting to read these values from ~/.ssh/config, but
+  that's more than I need at the moment.")
+
+(defun ssh/sudo-buffer ()
+  "Open the current buffer with sudo rights."
+  (interactive)
+  (with-current-buffer (current-buffer)
+    (if (s-starts-with? "/ssh:" buffer-file-name)
+        (message "[ssh.el] calling ssh/sudo-buffer for remote files isn't currently supported")
+      (find-file (format "/sudo::%s" buffer-file-name)))))
+
+(defun ssh/cd-home ()
+  "Prompt for an SSH host and open a dired buffer for wpcarro on that machine."
   (interactive)
-  (find-file "/ssh:wpcarro@desktop:~"))
+  (let ((machine (completing-read "Machine: " ssh/hosts)))
+    (find-file (format "/ssh:wpcarro@%s:~" machine))))
 
 (provide 'ssh)
 ;;; ssh.el ends here