12

I have set up custom $PATH in my ~/.bash_profile on a remote machine (for programs installed user-locally by nix and cabal).

I use eshell and tramp to issue commands on the remote machine (cd /remotehost:somedir; then commands). (I chose this method instead of the common SSH-sessions in a terminal primarily because I'm using a bad connection and SSH-sessions get interrupted very often, so I can't count on being able to login, cd, and issue a command before the connection is interrupted.)

Unfortunately, my custom PATH is not honored in this situation, and some of the programs are not found.

What would be the nicest way to solve this problem?

1

1 Answer 1

8

This question has been already answered by rekado (thanks!) (as a reply to another more general question about eshell):

You can configure TRAMP to respect the PATH variable on the remote machine (for remote eshell sessions) by adding 'tramp-own-remote-path to the list 'tramp-remote-path:

(add-to-list 'tramp-remote-path 'tramp-own-remote-path)

By default, eshell will not adopt the remote PATH settings.

As for other environment variables, there is no special approach as for PATH: one can set them through tramp-remote-process-environment (as documented in https://www.gnu.org/software/emacs/manual/html_node/tramp/Remote-processes.html):

(add-to-list 'tramp-remote-process-environment
              (format "DISPLAY=%s" (getenv "DISPLAY")))

and I don't know of a way that would read the ones set in the remote ~/.bash_profile. So you need to repeat them in this variable on the local side in Emacs as a workaround, which is not totally convenient because different remote hosts might need different values.

As for EDITOR specifically, of course, doing it with with-editor would be more convenient and appropriate.

3
  • 2
    I don't see that this works. Perhaps, that's because I set and export a custom PATH in ~/.bash_profile (contrary to ~/.profile) which I have seen in some docs concerning these tramp-* vars... Jan 26, 2015 at 20:01
  • 1
    This was fixed in Tramp last December. Try the development version of Tramp. Jan 27, 2015 at 7:47
  • 3
    It might be worth pointing out in this answer that adding 'tramp-own-remote-path to tramp-remote-path causes tramp to open a login shell (using the -l argument), thereby sourcing ~/.profile – this means that per-host customization can be done in ~/.profile for things other than PATH.
    – emdash
    Apr 12, 2020 at 10:05

Your Answer

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

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