VSCode修改终端为git-bash

2021/4/22 VSCode

转载自 vscode中内置集成终端显示为git(bash.exe) (opens new window)

TIPS

背景

VSCode的终端默认是 cmd,有时候在终端中想用下 Linux 中的命令不得行

  1. 打开终端设置

    • 左下角的齿轮
    • Ctrl + `
    • 左上角: 文件 > 首选项 > 设置
    • Ctrl + Shift + P,然后在里面搜
    • 在终端里面选择配置终端设置
    • ...

    进入 setting.json

  2. 修改终端

    terminal.integrated.shell.windows 的值改成Git安装目录中的 bash.exe 路径(要双斜杠),如:

    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
    
    1

    然后重启,打开终端(快捷键 Ctrl + ~ )就是 git-bash

    TIPS

    setting.json 中还有一个属性 terminal.integrated.automationShell.windows,它的说明是:一个路径,设置后将替代 terminal.integrated.shell.windows,并忽略与自动化相关的终端使用情况(例如任务和调试)的 shellArgs 值。

    比如设置为:

    "terminal.integrated.automationShell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
    
    1

    但是试了没效果,启动还是 cmd,输入 bash 还报错,可能是设置的不对吧,不晓得啥子原因

    2021年9月,突然发先新版本VSCode使用上述配置失效,终端启动默认为powershell,在VSCode升级至1.57.1(2021.6.17)时:

    此项已弃用,配置默认 shell 的新推荐方法是在 #terminal.integrated.profiles.windows# 中创建一个终端配置文件,并将其配置文件名称设置为 #terminal.integrated.defaultProfile.windows# 中的默认值。此操作当前将优先于新的配置文件设置,但将来会发生更改。

    新的配置项 (opens new window)

    {
       "terminal.integrated.profiles.windows": {
          "Git Bash": {
             "path": "C:\\Program Files\\Git\\bin\\bash.exe",
          }
       },
       "terminal.integrated.defaultProfile.windows": "Git Bash",
    }
    
    1
    2
    3
    4
    5
    6
    7
    8

    如果terminal.integrated.defaultProfile.windows的选项中已经有了Git Bash,则无需再配置terminal.integrated.profiles.windows

  3. 切换终端

    • 切换成 cmd:在终端中输入 cmd
    • 切换成 powershell:在终端中输入 powershell
    • 切换成 git-bash:在终端中输入 bash
最近更新: 2023年03月21日 14:47:21