summaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2024-02-23 14:21:51 +0100
committerMartin Polden <mpolden@mpolden.no>2024-02-23 14:28:17 +0100
commit3bf5950d0279b41aa0af097cc6098afd83428042 (patch)
tree1c2df50187297c209e34a18f48b31c7ca1e7ccac /lisp
parent11a72e9f32147f4d91ac4e8da12d513f66fcdc1a (diff)
tramp: stop setting tramp-default-proxies-alist
This confuses TRAMP when passing explicit usernames, e.g. /ssh:root@myhost.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-tramp.el40
1 files changed, 20 insertions, 20 deletions
diff --git a/lisp/init-tramp.el b/lisp/init-tramp.el
index ae279d0..6c3fdcd 100644
--- a/lisp/init-tramp.el
+++ b/lisp/init-tramp.el
@@ -6,23 +6,27 @@
"Add a sudo-like TRAMP method to FILENAME.
If FILENAME already contains a sudo-like method, return FILENAME
-unchanged. If FILENAME is accessed over SSH, replace \"/ssh:\"
-with \"/sudo:\". Otherwise, assume FILENAME is a local path and
-prefix it with \"/sudo::\".
-
-If doas is available on the remote host, the doas method is used
-instead of sudo."
- ;; sudo:remote-host works because of the special tramp-default-proxies-alist
- ;; configuration below
- (let* ((splitname (split-string filename ":"))
- (method (car splitname)))
- (if (member method '("/sudo" "/doas"))
+unchanged. If FILENAME is accessed over SSH, replace
+\"/ssh:host\" with \"/ssh:host|sudo:\". Otherwise, assume
+FILENAME is a local path and prefix it with \"/sudo::\".
+
+If doas is available, that method is used instead of sudo."
+ (let* ((parts (split-string filename ":"))
+ (method (substring (nth 0 parts) 1))
+ (host (nth 1 parts))
+ (hop-method (when host (nth 1 (split-string host "|"))))
+ (sudo-methods '("sudo" "doas")))
+ (if (or (member method sudo-methods)
+ (member hop-method sudo-methods))
filename
- (let* ((is-ssh (equal method "/ssh"))
- (sudo-method (concat (if (executable-find "doas" t) "/doas" "/sudo")
- (if is-ssh "" ":")))
- (components (if is-ssh (cdr splitname) splitname)))
- (mapconcat 'identity (cons sudo-method components) ":")))))
+ (let* ((sudo-method (if (executable-find "doas" t) "doas" "sudo"))
+ (sudo-hop (when (equal method "ssh")
+ (concat host "|" sudo-method ":"))))
+ (if sudo-hop
+ (mapconcat 'identity (append (list (concat "/" method) sudo-hop)
+ (nthcdr 2 parts))
+ ":")
+ (concat "/" sudo-method "::" filename))))))
(defun mpolden/sudo-find-file (&optional arg)
"Find file and open it with sudo.
@@ -43,10 +47,6 @@ With a prefix ARG prompt edit currently visited file using sudo."
("C-x !" . mpolden/sudo-current-file))
:config
- ;; make sudo:remote-host work as expected
- (add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
- (add-to-list 'tramp-default-proxies-alist
- '((regexp-quote (system-name)) nil nil))
;; use path configured by remote host
(add-to-list 'tramp-remote-path 'tramp-own-remote-path))