Tilmann Singer <[email protected]> writes:
Hi Til,
> Thanks. Unfortunately it is not sufficient for my use case because the
> setup on each host varies.
>
> I was hoping that it is possible to add a new custom tramp method, e.g.
> called "sudoi", and after some dabbling around came up with this:
>
> #+begin_src elisp :results none
> (add-to-list 'tramp-methods
> '("sudoi" (tramp-login-program "env")
> (tramp-login-args
> (("sudo")
> ("-u" "%u") ("-i") ("%l")))
> (tramp-remote-shell "/bin/sh")
> (tramp-remote-shell-args ("-c"))))
> #+end_src
>
> which is a stripped copy of the entry for "sudo" with the sudo option
> "-c" replaced by "-i". Now this remote path:
>
> /ssh:example.com|sudoi:[email protected]:
>
> sources the remote profile. Not sure if 'tramp-methods was meant to be
> extended this way, but it works for me so far. And it has the benefit
> that when the configuration is not present, it will fail right away with
> the message "Method ‘sudoi’ is not known".
Of course, it is possible to add a new method to tramp-methods. However,
there are disadvantages. For example, your new method won't benefit from
new/changed parameters of methods in tramp-methods, unless you care and
check regularly. For the sudo method, there is on my todo list to
empower it for direct async connections. This requires changes in
tramp-methods.
Furthermore, tramp-methods isn't the only change for method
configuration. For the sudo method, we configure also
tramp-default-user-alist (default user "root"),
tramp-completion-function-alist (user/host name completion), "~/" in
expand-file-name, tramp-default-proxies-alist (multi-hop
configuration). I don't know whether you need this for your own method,
but you see, it is rather complex.
Instead, the Tramp manual recommends to adapt a parameter for a given
method of tramp-methods, specific to a remote target (a regexp). See the
discussion in (info "(tramp) Predefined connection information") . In your
case, I recommend you to apply
--8<---------------cut here---------------start------------->8---
(add-to-list 'tramp-connection-properties
(list (regexp-quote "/sudo:user@host:")
"login-args"
'(("SUDO_PROMPT=P\"\"a\"\"s\"\"s\"\"w\"\"o\"\"r\"\"d\"\":")
("sudo") ("-u" "%u") ("-i") ("%l"))))
--8<---------------cut here---------------end--------------->8---
> cheers, Til
Best regards, Michael.