使用 cli 更改 VsCode 终端选项卡图标和颜色

问题描述 投票:0回答:3

我希望能够使用 cli 更改终端选项卡和颜色的颜色和图标。

enter image description here

这可能就是结果
enter image description here

原因是使用恢复终端扩展,然后自动设置每个终端的不同图标和颜色。

但是我无法通过文档找到它,这是否可行?

visual-studio-code
3个回答
3
投票

如果有人仍然感兴趣,可以这样做。 至少现在您可以在扩展设置中指定终端的配置文件:

"restoreTerminals.terminals": [
    {
      "profile": "Coverage",
      "splitTerminals": [
        {
          "name": "Coverage",
        }
      ]
    },
    {
      "profile": "Server",
      "splitTerminals": [
        {
          "name": "Server",
        }
      ]
    }
  ]

因此,您实际上可以为您想要的每个终端创建一个配置文件,如下所示:

"terminal.integrated.profiles.windows": {
    "Coverage": {
      "path": ["D:\\Program Files\\Git\\bin\\bash.exe"],
      "icon": "beaker",
      "color": "terminal.ansiGreen"
    },
    "Server": {
      "path": ["D:\\Program Files\\Git\\bin\\bash.exe"],
      "icon": "server",
      "color": "terminal.ansiMagenta"
    }
  },

完成:

Terminals

此方法不再有效,请参阅下面的方法

我现在使用扩展程序Terminals Manager

你可以看一下文档,但这是我当前的扩展设置:

  "terminal.integrated.hideOnStartup": "always",
  "terminal.integrated.enablePersistentSessions": false,

  "terminals.invertCommandsAndDescription": false,
  "terminals.showCommands": false,
  "terminals.showDescriptions": true,
  "terminals.sortTerminals": false,
  "terminals.env": {},
  "terminals.multiplexer": "screen",
  "workbench.startupEditor": "readme",
  "terminals.autorun": true,
  "terminals.autokill": true,

最后,您可以单独配置您的终端。这是我的配置:

"terminals.terminals": [
    {
      "name": "Sonar",
      "description": "Terminal to run static analyzer sonar-scanner",
      "icon": "checklist",
      "color": "terminal.ansiCyan",
      "recycle": true
    },
    {
      "name": "Test",
      "description": "Terminal to run testes",
      "color": "terminal.ansiGreen",
      "icon": "beaker",
      "command": "npm run testCov",
      "execute": false,
      "recycle": true
    },
    {
      "name": "Server",
      "description": "Terminal to run the current program",
      "color": "terminal.ansiMagenta",
      "icon": "server",
      "command": "npm run startDev",
      "execute": false,
      "recycle": true,
      "focus": true
    },
    {
      "name": "Git",
      "description": "Terminal to run git and other misc commands",
      "color": "terminal.ansiYellow",
      "icon": "git-branch",
      "recycle": true
    }
  ],

2
投票

在 settings.json 文件中,您可以指定配置文件中图标的

icon
color
。 例如:

"terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash",
            "icon": "terminal-bash", //what icon to use
            "color": "terminal.ansiGreen" //color of icon
        }
    },
"terminal.integrated.defaultProfile.windows": "Git Bash",

使用您链接到的扩展会产生如下结果(使用他们在扩展文档中列出的示例 json 设置):

Icons

看起来该扩展使用了您的默认终端配置文件(实际上查看其源代码,它甚至不知道默认配置文件是什么,只是调用 VS Code API 命令来生成新终端),并应用所述配置文件的设置,因此您将仅限于一种颜色/图标。


0
投票

,我的问题的目的是能够更改每个图标和颜色,api 应该是黄色,云蓝色,...我确实更新了我的问题,以便更准确地描述我尝试存档的内容。

如果可行,那不是 VSCode 本身,而是通过扩展。

“在创建时为终端选项卡分配唯一/随机颜色/图标”(

microsoft/vscode
问题 127951)很清楚:

作为扩展关闭可以做到这一点

OP 补充道:

为了使其可行,我们首先需要了解如何通过 api 更改颜色

随后是问题 128228,并在 PR 130123“最终确定终端颜色 API”中实现

© www.soinside.com 2019 - 2024. All rights reserved.