11

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?

  • Other related discussions: [Tramp using ssh does not source .bash_profile / .profile](http://stackoverflow.com/q/10463152/94687), [emacs tramp how to avoid bash_profile](http://stackoverflow.com/q/10712654/94687), [how to get bash_profile out of the way?](https://lists.gnu.org/archive/html/tramp-devel/2012-06/msg00003.html), ['exec /bin/bash --login' in ~/.profile](http://comments.gmane.org/gmane.emacs.tramp/7632), ... – imz -- Ivan Zakharyaschev Jan 26 '15 at 21:47

1 Answers1

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.

  • 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... – imz -- Ivan Zakharyaschev Jan 26 '15 at 20:01
  • 1
    This was fixed in Tramp last December. Try the development version of Tramp. – Michael Albinus Jan 27 '15 at 07:47
  • 2
    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 '20 at 10:05