问题描述
我正在使用 ConEmu 并且对它完全满意,除了如果我使用 PuTTY 进行 SSH 访问,然后我可以在远程机器上运行命令,如 vim 或 nano 或 mcedit 或其他打开某种诅咒的命令-interface 并且我可以看到控制台命令历史记录,但是当我使用 CygWin SSH 客户端或 OpenSSH for Windows 时,我在运行 vim/nano/mcedit/whatever else 后无法再看到命令历史记录.
I am using ConEmu and am totally satisfied with it except for the fact that if I use PuTTY for SSH access, I can then run commands on the remote machine like vim or nano or mcedit or others which opens some kind of a curses-interface and I can see the console commands history, but when I use CygWin SSH client or OpenSSH for Windows I cannot see the commands history anymore after running vim/nano/mcedit/whatever else.
当我退出那些程序(vim 中的:wq,mcedit 中的 Esc 键,nano 中的 Ctrl^X)时,我可以看到之前执行的所有命令,就像这样(如果我使用 PuTTY):
When I quit those programs (:wq in vim, Esc key in mcedit, Ctrl^X in nano) I can see all the previous commands executed, like this (if I use PuTTY):
- 运行 PuTTY 并连接到某个主机
- 你会在历史上看到类似的东西:
主机$ whoami
用户
主机$ vim
...在 vim 中做一些事情然后按 :wq
你应该看到这个:
=== 切===
主机$ whoami
用户
主机$ vim
主机$
===剪切===
=== Cut ===
host$ whoami
user
host$ vim
host$
=== Cut ===
之前的所有命令 (whoami) 都是可见的.但是,如果我运行 ConEmu,然后使用来自 CygWin(或 OpenSSH 客户端,没关系)的 SSH 客户端,则会发生以下情况:
all the previous commands (whoami) are visible. However if I run ConEmu and then use SSH client from CygWin (or OpenSSH client, it doesn't matter) the following happens:
- 运行 ConEmu
- ssh user@somehost主机$ whoami
用户
主机$ vim
...在 vim 中做一些事情然后按 :wq
现在屏幕是空的!没有历史!你只看到这个:
And now the screen is empty! No history! You just see this:
=== 切===
主机$
===剪切===
=== Cut ===
host$
=== Cut ===
好像没有处决 whoami.mcedit、nano 或任何其他具有类似屏幕"功能的程序也会发生同样的情况.在 Midnight Commander 中使用 Ctrl-O 也会发生同样的情况,在 PuTTY 中一切都很好,但是当在 ConEmu(或 OpenSSH Windows 客户端)中使用来自 CygWin 的 ssh 并运行 Midnight Commander 时,每个 Ctrl-O 只显示一个空的历史记录.好像之前没有输入任何内容.真的一点都不好看.
As if no whoami was executed. Same happens for mcedit, nano or any other programs that has something like a "screen". Also same happens with Ctrl-O in Midnight Commander, in PuTTY everything is nice, but when using ssh from CygWin in ConEmu (or OpenSSH Windows client) and running Midnight Commander each Ctrl-O just shows an empty history. As if nothing was typed previously. That is really not nice at all.
有什么办法可以解决吗?
Is there any way to fix that?
推荐答案
PuTTY.exe
的标准 TERM
环境变量是 xterm
和这主要适用于 Cygwin ssh.exe
以及.但是,ssh.exe
更好的 TERM
环境变量是 cygwin
.
The standard TERM
environment variable for PuTTY.exe
is xterm
and that will mostly work for Cygwin ssh.exe
as well. However, a better TERM
environment variable for ssh.exe
is cygwin
.
当您使用 Cygwin ssh.exe
连接到另一个系统时,Cygwin 处理您的转义序列,而不是 ConEmu.事实上,无论您是在 ConEmu 内部还是外部运行 ssh.exe
,您都会得到相同的行为.所以问题根本与 ConEmu 无关,至少与它的 ANSI 处理器无关.
When you use Cygwin ssh.exe
to connect to another system, Cygwin processes your escape sequences, not ConEmu. In fact you get the same behavior whether you are running ssh.exe
inside or outside of ConEmu. So the problem is not really related to ConEmu at all, at least not its ANSI processor.
解决方案是对远程系统上的 TERM
环境变量使用 cygwin
.事实上,SSH 客户端和服务器会自动合作为您执行此操作.但是,您可能不小心在 .bash_profile
或其他内容中使用 xterm
覆盖了提供的 TERM
变量.在这种情况下,退出编辑器后恢复屏幕缓冲区的转义序列对于 Cygwin ANSI 处理器将不正确.
The solution is to use the cygwin
for the TERM
environment variable on the remote system. In fact, the SSH client and server cooperate to do this for you automatically. But perhaps you have accidentally overridden the supplied TERM
variable with say xterm
in your .bash_profile
or whatever. In that case, the escape sequence to restore the screen buffer after exiting the editor won't be correct for the Cygwin ANSI processor.
您可以进行此测试以检查这是否能解决您的问题:
You can do this test to check whether this solves your problem:
$ export TERM=xterm
$ vim
$ # the screen before is cleared
$ export TERM=cygwin
$ vim
$ # the screen buffer is restored
这篇关于conmu + ssh 清除控制台历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!