在 vscode 中更改集成终端标题

Posted

技术标签:

【中文标题】在 vscode 中更改集成终端标题【英文标题】:Change Integrated Terminal title in vscode 【发布时间】:2017-08-11 10:02:13 【问题描述】:

我们可以使用View菜单中的Integrated Terminal功能在vscode中打开命令提示符。

我们甚至可以打开多个终端,如下图:

有什么办法可以更改终端的标题吗?

1: cmd.exe 将是构建终端 2: cmd.exe 将是观看终端

我浏览了integrated terminal 文档,但没有找到方法。

【问题讨论】:

我对同样的事情感兴趣,我希望能够更改标题,以便知道我要通过 ssh 访问的机器的主机名 遗憾的是,微软关闭并锁定了github.com/Microsoft/vscode/issues/63264 的功能请求,现在我们需要一个用于自动重命名终端窗口的扩展,因为手动重命名在实际使用中几乎无用。 【参考方案1】:

在windows中按Ctrl + Shift + P,然后输入:终端:重命名,您可以在此处更改终端名称/标题

【讨论】:

感谢您的回答 对于 Mac,是 cmd + shift + p【参考方案2】:

有时,插件会删除默认的键盘快捷键绑定。

在键盘快捷键中查找“terminal.rename”,然后将键盘快捷键编辑为您喜欢的快捷键。

要应用您的快捷方式,请确保您的光标在键入之前位于窗口的编辑部分。而不是终端部分。

【讨论】:

【参考方案3】:

在 v1.41 中有一个新命令可以这样使用:


  "key": "ctrl+t",
  "command": "workbench.action.terminal.renameWithArg",
  "args": 
      "name": "remote"
  

如果您有一些经常使用的名称,例如您经常使用的“remote”或“build”。

【讨论】:

【参考方案4】:

在 v1.61 中,可以使用变量设置终端名称。见terminal custom titles in release notes。

终端名称通常是它们所在进程的名称 有关联。因此,很难区分 他们。

我们现在支持同时配置标题和描述以帮助 这使用terminal.integrated.tabs.title 中描述的变量和 terminal.integrated.tabs.description 设置。

当前默认值为:


  "terminal.integrated.tabs.title": "$process",
  "terminal.integrated.tabs.description": "$task$separator$local$separator$cwdFolder"

可用的变量有:

$cwd - The terminal's current working directory  
$cwdFolder - The terminal's current working directory.  
$workspaceFolder - The workspace in which the terminal was launched.  
$local - Indicates a local terminal in a remote workspace.  
$process - The name of the terminal process.  
$separator - A conditional separator (" - ") that only shows when surrounded by variables with values or static text.  
$sequence - The name provided to xterm.js by the process.  
$task - Indicates this terminal is associated with a task.  

看起来$task 变量就是您要查找的变量。

【讨论】:

【参考方案5】:

对于 VSCode 1.63(2021 年 11 月),输入“<blank>”(即空字符串)作为名称将恢复该终端的默认名称。

见issue 134020

例如:

如果我的设置是 $cwd$separator$process 并且我将终端命名为“foo”。 如何将“foo”重置为$cwd$separator$process的值? 我的建议是,如果您尝试提交一个空白名称,该名称会自动重置为您的设置值。

【讨论】:

以上是关于在 vscode 中更改集成终端标题的主要内容,如果未能解决你的问题,请参考以下文章

VS Code 集成终端的颜色主题

VSCode 更改默认终端

安装 zsh 并更改字体样式后,我在 VSCode 中的终端字体很小?

VS Code 集成终端在粘贴时弄乱了剪贴板 python 代码

VSCode 未显示源代码控制 git 面板中的更改

VSCode + WSL Remote + Git:同步更改需要很长时间