使用VSCode远程SSH扩展和tmux出现-bash: __vsc_prompt_cmd_original: command not found错误。

6
大约一周前,我注意到使用Remote SSH Extension和tmux时出现了一个奇怪的问题。在打开终端并启动tmux后,每个命令后都会在控制台上打印以下内容:-bash: __vsc_prompt_cmd_original: command not found
如果我检查输出选项卡中的日志(远程 Pty 主机)部分,我会看到以下内容:
[2022-08-19 14:48:23.822] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q --header='Metadata:true' -O - http://169.254.169.254/metadata/instance?api-version=2019-03-11\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s --header='Metadata:true' http://169.254.169.254/metadata/instance?api-version=2019-03-11\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.890] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q  -O - http://169.254.169.254/latest/meta-data/instance-id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s  http://169.254.169.254/latest/meta-data/instance-id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.896] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q  -O - http://169.254.169.254/metadata/v1/id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s  http://169.254.169.254/metadata/v1/id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:48:23.900] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/sh" and args ["-c","wget --version > /dev/null\nif [ $? -eq 0 ]\nthen\n\twget --connect-timeout=7 --tries=1 --dns-timeout=7 -q --header='Metadata-Flavor:Google' -O - http://metadata.google.internal/computeMetadata/v1/instance/id\nelse\n\tcurl --version > /dev/null\n\tif [ $? -eq 0 ]\n\tthen\n\t\tcurl --connect-timeout 7 -s --header='Metadata-Flavor:Google' http://metadata.google.internal/computeMetadata/v1/instance/id\n\tfi\nfi\nexit 0"]
[2022-08-19 14:52:08.838] [ptyhost] [warning] Shell integration cannot be enabled for executable "/bin/tmux" and args undefined

最后一行似乎有些令人担忧,如果我使用远程SSH扩展在另一个主机上(其中tmux正常工作),那么该行不会出现(这让我相信这种行为可能存在联系)。
两个远程主机都启用了终端集成(禁用终端集成似乎没有任何作用)。查看VSCode终端集成的设置,我注意到tmux未列为终端集成支持的shell之一(只有bash、pwsh和zsh)。我还看到一个警告,复杂的bash PROMPT_COMMAND也可能会破坏事情(尽管在其他远程主机上编辑我的PS1以打印我所在的github分支是有效的)。设置中的链接(我已经在此处复制了)是损坏的,该页面上没有#_complex-bash-promptcommand锚点,因此这可能是一个误导。
有什么想法吗?我应该提交一个VSCode问题吗?我完全迷失了吗?

这里也有同样的问题,不知道从哪里开始解决。你找到解决方案了吗? - Lewistrick
不,而且问题仍在持续。我有点希望最终会有一个无意中修复这个问题的更新。 ¯\(ツ) - Alex Gurvich
2个回答

10
您可以测试以下方法。
使用像nano或vim这样的编辑器,将下列行添加到您的.bashrc文件中: unset PROMPT_COMMAND
它将在下一个会话时生效。
要立即应用更改以使其在当前shell会话的整个生命周期内生效,请在终端窗口中键入以下命令: unset PROMPT_COMMAND

1
啊,确实,这似乎解决了问题!我没有意识到$PROMPT_COMMAND是调用__vsc_prompt_cmd_original的东西。事实上,我根本没有想到$PROMPT_COMMAND是一个东西。干杯! - Alex Gurvich

1

我也在使用VSCode时遇到了同样的提示:"-bash: __vsc_prompt_cmd_original: command not found"。要消除此提示,请禁用以下设置:

{
  "terminal.integrated.shellIntegration.enabled": false
}

或者UI设置: 在此输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接