From 3bf5950d0279b41aa0af097cc6098afd83428042 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 23 Feb 2024 14:21:51 +0100 Subject: tramp: stop setting tramp-default-proxies-alist This confuses TRAMP when passing explicit usernames, e.g. /ssh:root@myhost. --- lisp/init-tramp.el | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'lisp') 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)) -- cgit v1.2.3