0

Background

The actual problem I'm trying to solve is that Tramp does not use the PATH of the remote machine it's SSH-ing to. One workaround is to from the client set PATH depending on which machine Tramp is visiting.

The emacs manual describes how to set this up for a single machine.

Single machine matching

#+begin_src bash :dir /ssh:hype:/
hostname
echo $PATH
mmlsfs -h
#+end_src

#+RESULTS[d90ea0d78b70c282ea255dc55e1aad9261bc8ca9]:
: hype
: /usr/bin:/bin:/sbin:/usr/sbin:/usr/local/sbin
: bash: line 4: mmlsfs: command not found


#+begin_src elisp
(connection-local-set-profile-variables 'remote-path-with-gpfs
 '((tramp-remote-path . ("/usr/lpp/mmfs/bin/" tramp-default-remote-path))))

(connection-local-set-profiles
 '(:application tramp :machine "hype") 'remote-path-with-gpfs)
#+end_src

#+RESULTS[9e4a07fa589fb89a3ba5f5e00af3fddd222aa33a]:
:  ((:application tramp :machine "hype")
:   remote-path-with-gpfs)
:  ((:application tramp)
:   tramp-connection-local-default-profile))

#+begin_src bash :dir /ssh:hype:/
hostname
echo $PATH
mmlsfs -h
#+end_src

#+RESULTS[a59792ebf5e54f55012f1ab191bf160eaa927ed5]:
#+begin_example
hype
/usr/lpp/mmfs/bin/:/usr/bin
Usage:
   mmlsfs {Device | all | all_local | all_remote} [-A] [-B] [-d] [-D]
...
#+end_example

And for a single machine this works well. But I would like to set the same PATH for a couple of hundred machines. That or have Tramp inherit PATH from the machine it lands on.

I have tried to grok the code for the subst connection-local-get-profiles in files-x.el but have yet to understand if it does anything but literal equality checks.

Hypothethical example

If, for example, regexes were accepted and matched the following criteria would match both machines named n1 and n500.

(connection-local-set-profiles
 '(:application tramp :machine "n[:digit:]+") 'remote-path-with-gpfs)

This would result in the following code block evaluating like it did on hype.

#+begin_src bash :dir /ssh:hype|su:root@hype|ssh:n1:/
hostname
echo $PATH
mmlsfs
#+end_src

#+RESULTS[c8d522bc1e3da7031ae726e4a987a3b3f441f771]:
: n1
: /usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
: bash: line 4: mmlsfs: command not found

Question

Is it possible to match multiple machines with a criteria. Or is it possible to have Tramp inherit PATH from the machine it lands on.

I could iterate over a generated list of all the machines I want to match and add one rule per machine. But that would mean Emacs having to evaluate all hundred criteria per connection it ever sets up, which seems less than ideal.

1 Answer 1

1

connection-local-criteria-alist uses strings for the properties, not regexps. But you can simply leave the :machine property out, like

(connection-local-set-profiles
 '(:application tramp) 'remote-path-with-gpfs)

You can also use another property for identifying the hosts you are already in, like :user or :protocol.

2
  • Is there any harm in having a path in Tramps PATH that does not exist?
    – Rovanion
    Sep 14, 2023 at 14:53
  • There shouldn't be a problem. Sep 15, 2023 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.