【问题标题】:TRAMP ignores tramp-remote-pathTRAMP 忽略 tramp-remote-path
【发布时间】:2014-12-25 04:11:12
【问题描述】:

我的 .emacs 中有以下内容:

(require 'tramp)
(add-to-list 'tramp-remote-path "/some/path")
(add-to-list 'tramp-remote-path 'tramp-default-remote-path)

所以当我使用tramp over ssh 打开一个文件时,我希望我的PATH 包含/some/path。相反,运行 M-! echo $PATH 会返回

/bin:/usr/bin:/usr/sbin:/usr/local/bin

即使我在.bashrc.profile 中设置了export PATH=/hwdisks/data/modules/pkg/git/1.8.4.1/bin/git:$PATHPATH 也没有正确设置。

在tramp日志*debug tramp/ssh remotehost*中,我可以看到tramp明确设置PATH

12:28:34.202135 tramp-send-command (6) # PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin; export PATH

如果我在.bashrc 中包含echo "in .bashrc",它会出现在tramp 日志中,所以我知道tramp 正在阅读它。

如何让流浪汉使用正确的PATH

Emacs 版本:24.2.1
流浪汉版本:2.2.3-24.1

【问题讨论】:

    标签: emacs tramp


    【解决方案1】:

    尴尬的是,答案在流浪汉手册中:

    另一种可能性是在您登录时重用远程帐户的路径设置。通常,这些设置会被覆盖,因为它们可能对tramp没有用处。占位符 tramp-own-remote-path 保留这些设置。您可以通过

    激活它
    (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
    

    我仍然不确定为什么它会忽略添加到 tramp-remote-path 的其他路径。

    【讨论】:

    • 感谢您花时间回到这里并在找到此答案后发布。这是我可以对tramp-remote-path 做的唯一对路径有任何实际影响的事情。
    • 我认为当 TRAMP 尝试以described here 启动“远程程序”时使用tramp-remote-path,而不是实际设置$PATH 变量。出于这个原因,我认为您不会在远程 shell 中看到您的更改,但如果您尝试使用magit,它将根据您的内容在远程主机上查找gittramp-remote-path 中指定。
    【解决方案2】:

    我在流浪汉手册中阅读并尝试过。 添加了

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

    然后退出emacs,删除~/.emacs.d/tramp,并按照here的说明重新启动

    但是M-! echo $PATH 仍然显示tramp-default-remote-path 的值,而不是我在.bashrc 中设置的值。

    问题似乎是我对如何加载配置文件的理解。 tramp 调用远程 shell 获取远程 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
    

    由于 bash 作为登录 shell 和 /bin/sh 调用,它读取为 .profile 而不是 .bash_profile.bashrc

    我在 bash 手册页中找到了这个:

    如果使用名称 sh 调用 bash,它会尝试模仿 sh 的历史版本尽可能接近,同时符合 POSIX 标准也是如此。当作为交互式登录 shell 调用时,或者 带有 --login 选项的非交互式 shell,它首先尝试读取和 按顺序从 /etc/profile 和 ~/.profile 执行命令。这 --noprofile 选项可用于禁止此行为。当作为 名为 sh 的交互式 shell,bash 查找变量 ENV,展开 如果已定义,则为它的值,并使用扩展值作为文件名 阅读和执行。由于作为 sh 调用的 shell 不会尝试读取和 从任何其他启动文件执行命令,--rcfile 选项没有 影响。使用名称 sh 调用的非交互式 shell 不会尝试 读取任何其他启动文件。当作为 sh 调用时,bash 进入 posix 模式 读取启动文件后。

    我通常只配置 ~/.bashrc~/.bash_profile 为了让 tramp 正常工作看起来我应该将我的 .bash_profile 移动到 .profile

    希望这对其他人有所帮助。

    • GNU Emacs:25.0.94.2 Tramp:2.2.13.25.1

    【讨论】:

      猜你喜欢
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多