TRAMP ignores tramp-remote-path

拥有回忆 提交于 2019-12-05 03:45:14

Embarrassingly, the answer is in the tramp manual:

Another possibility is to reuse the path settings of your remote account when you log in. Usually, these settings are overwritten, because they might not be useful for tramp. The place holder tramp-own-remote-path preserves these settings. You can activate it via

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

I'm still not sure why it ignores the other paths added to tramp-remote-path.

Oden Godner

I read this in tramp manual and tried it. Added

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

Then exited emacs, removed ~/.emacs.d/tramp, and restarted as explained here

But M-! echo $PATH still shows the value of tramp-default-remote-path instead of the value set in my .bashrc.

The issue looks to be my understanding of how profiles are loaded. The way tramp calls the remote shell to get the remote PATH:

/bin/sh -l -c 'echo $PATH'
/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

Since bash is call as login shell and as /bin/sh it reads .profile instead of .bash_profile or .bashrc.

I found this in bash manual page:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode after the startup files are read.

I usually configure only ~/.bashrc and ~/.bash_profile For tramp to work properly looks like I should move my .bash_profile to .profile

Hope this helps others.

  • GNU Emacs: 25.0.94.2 Tramp: 2.2.13.25.1
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!