简体   繁体   English

Emacs:流浪汉不起作用

[英]Emacs: Tramp doesn't work

I tried to open a remote file via Emacs via Tramp.我试图通过 Emacs 通过 Tramp 打开一个远程文件。

(require 'tramp)
(setq tramp-default-method "ssh")

I get a message from Emacs我收到来自 Emacs 的消息

Tramp: Waiting for prompts from remote shell流浪汉:等待来自远程 shell 的提示

Emacs hung and did not respond to any action after that Emacs 挂了,之后没有响应任何操作

Emacs was installed on Windows; Emacs 安装在 Windows 上; the remote file was on a Linux machine.远程文件在 Linux 机器上。

If the account you're connecting to uses some weird fancy shell prompt, then there is a good chance that this is what makes tramp trip.如果您连接的帐户使用了一些奇怪的花哨的 shell 提示,那么很有可能这就是造成流浪者旅行的原因。

Log in as root, then enter以 root 身份登录,然后输入

PS1="> "

(that's a normal, standard shell (ZSH, BASH, younameit) prompt, one that tramp will understand) then switch to the user account, and launch emacs -q (to make sure that your .emacs is not causing this mess) and try to Cx Cf /sudo:root@localhost:/etc/hosts and see what's what. (这是一个正常的标准 shell(ZSH、BASH、younameit)提示,一个tramp会理解的)然后切换到用户帐户,并启动emacs -q (以确保您的.emacs不会造成这种混乱)并尝试到Cx Cf /sudo:root@localhost:/etc/hosts看看是什么。

You can (not recommended) also customize the regexp that defines what tramp expects :您还可以(不推荐)自定义定义流浪者期望的正则表达式:

M-x customize-variable RET tramp-terminal-prompt-regexp

My approach :我的方法:

  1. Make sure the variable tramp-terminal-type is set to "dumb"确保变量tramp-terminal-type设置为“dumb”

Mx customize-variable RET tramp-terminal-type

  1. Test that in your .*shrc and serve the correct prompt :在您的 .*shrc 中测试并提供正确的提示:
 case "$TERM" in "dumb") PS1="> " ;; xterm*|rxvt*|eterm*|screen*) PS1="my fancy multi-line \\n prompt > " ;; *) PS1="> " ;; esac

Your Windows ssh client is the key here, and the 'ssh' Tramp method is almost certainly wrong.您的 Windows ssh 客户端是这里的关键,而“ssh” TRAMP 方法几乎肯定是错误的。

If you're using Cygwin, then you need to use the 'sshx' method, and you probably need to use ssh-agent to handle authentication.如果您使用的是 Cygwin,那么您需要使用 'sshx' 方法,并且您可能需要使用 ssh-agent 来处理身份验证。 Details are here: Using tramp with EmacsW32 and cygwin, possible?详细信息在这里: 使用带有 EmacsW32 和 cygwin 的tramp,可能吗?

I imagine the same applies to any stand-alone ssh client which does not require a full Cygwin installation, but does use the Cygwin DLLs.我想象中的一样适用于任何独立的SSH客户端不需要一个完整的Cygwin安装,但使用Cygwin的DLL文件。 (I mention this, because I'm pretty sure I remember seeing such a thing.) (我提到这一点,因为我很确定我记得看到过这样的事情。)

If you're using PuTTY then you want the 'plink' method, as Alex Ott pointed out.如果您使用 PuTTY,那么您需要“plink”方法,正如 Alex Ott 指出的那样。 If the Wiki doesn't suffice, a search here will probably turn up solutions for configuring that approach.如果 Wiki 不够用,在这里搜索可能会找到配置该方法的解决方案。

Other alternatives I can suggest are:我可以建议的其他替代方案是:

  1. Use the Cygwin-native Emacs.使用 Cygwin 原生 Emacs。 That will be slower than NTEmacs, but Tramp seems to work well with the 'ssh' method, and password-prompting works as well.这将比 NTEmacs 慢,但 TRAMP 似乎与 'ssh' 方法配合得很好,而且密码提示也有效。

  2. Host a Linux VM on your Windows box, and run Emacs on that.在您的 Windows 机器上托管 Linux VM,并在其上运行 Emacs。 That's a fairly large hoop to jump through, but it's my preferred way of using Tramp when working in Windows.这是一个相当大的障碍,但这是在 Windows 中工作时使用 Tramp 的首选方式

Well, this is a defect of tramp.嗯,这是流浪汉的缺陷。

The real solution is to prevent loading .bashrc when tramp is used.真正的解决方案是在使用tramp时防止加载.bashrc (because now it is PS1, but it can be PATH, or any other thing that your .bashrc will do that will displease tramp ...). (因为现在它是 PS1,但它可以是 PATH,或者你的.bashrc会做的任何其他会让tramp不高兴的事情......)。

This can be done by asking ssh to set an environment variable, and testing it in .bashrc :这可以通过要求 ssh 设置环境变量并在.bashrc测试来完成:

Add this to ~/.emacs :将此添加到~/.emacs

(require 'tramp-sh nil t) (setf tramp-ssh-controlmaster-options (concat "-o SendEnv TRAMP=yes " tramp-ssh-controlmaster-options))

and that at the beginning of ~/.bashrc :而在~/.bashrc的开头:

if [ ! -z ${TRAMP-x} ] ; then return fi

Another default of tramp is that it doesn't have a variable to pass random arguments to the ssh command, we have to piggy-back on tramp-ssh-controlmaster-options . tramp另一个默认设置是它没有一个变量来将随机参数传递给ssh命令,我们必须搭载tramp-ssh-controlmaster-options

Had you checked Emacs wiki for solution?您是否检查过Emacs wiki以获得解决方案? ssh is in PATH ? sshPATH It's also recommended to use plink on MS Windows - see section "Inline methods" in Tramp documentation还建议在 MS Windows 上使用plink - 请参阅 Tramp 文档中的“内联方法”部分

If the problem is your fancy custom prompt in the remote shell, an easy workaround is to add to your .bashrc or equivalent:如果问题是远程 shell 中的自定义提示,一个简单的解决方法是添加到您的.bashrc或等效文件中:

if [[ $TERM == "dumb" ]]; then
    export PS1="$ "
fi

After you define your PS1 .在你定义你的PS1

Note: the credit goes to ChasingLogic as this is their suggestion in this thread .注意:归功于ChasingLogic,因为这是他们在此线程中的建议。

By the way -- if You need tramp to sudo -- You can actually sudo without tramp using sudoedit .顺便说一句——如果你需要trampsudo你实际上可以使用sudoedit 没有tramp的情况下进行sudo

Currently I'm using this bash function:目前我正在使用这个 bash 函数:

erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM