我在Windows 10电脑上使用Visual Studio Code。我想把我的默认终端从Windows PowerShell更改为Ubuntu上的Bash(在Windows上)。

我该怎么做呢?


当前回答

离开@arielhad的解决方案…

我的VSCode版本是1.57.1。

打开settings.xml文件:

Ctrl + Shift + p 输入“Open Settings (JSON)”并选择。

增加如下内容:

"terminal.integrated.profiles.windows": {
    "PowerShell": {
        "path": [
            "${env:windir}\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
            "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
        ],
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": [
            "-NoLogo",
            "-ExecutionPolicy",
            "Bypass"
        ]
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "icon": "terminal-cmd"
    },

//START: THIS DOES NOT WORK
    "Git Bash": {
        "path": [
            "C:\\Program Files\\Git\\bin\\bash.exe",
        ],
        "source": "Git Bash",
        "icon": "terminal-bash"
    }
// END: THIS DOES NOT WORK

//START: THIS WORKS
    "GitBash": {
        "path": [
            "C:\\Program Files\\Git\\bin\\bash.exe",
        ],
        "icon": "terminal-bash"
    }
// END: THIS WORKS
}

我不知道为什么第二种方法有效,但它确实有效。“Git Bash”似乎是一个保留名称,我猜你不能设置路径。

其他回答

您可以通过按CTRL SHIFT P打开命令面板来更改终端

或者你可以点击顶部的“查看”,然后点击“打开命令面板”

然后输入Terminal:选择Default Profile

然后你输入你想要哪个终端。

如果你想要选择控制台的类型,你可以把它写在“keybinding”文件中。(该文件可以在以下路径“文件->首选项->键盘快捷键”中找到) `

//with this you can select what type of console you want
{
    "key": "ctrl+shift+t",
    "command": "shellLauncher.launch"
},

//and this will help you quickly change console
{ 
    "key": "ctrl+shift+j", 
    "command": "workbench.action.terminal.focusNext" 
},
{
    "key": "ctrl+shift+k", 
    "command": "workbench.action.terminal.focusPrevious" 
}`

转到>首选项>设置文件(或按Ctrl+,),然后点击右上角最左边的图标,“打开设置(JSON)”

在JSON设置窗口中,添加这个(在花括号{}内):

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"`

(在这里你可以放任何其他你想要的自定义设置)

签出该路径以确保bash.exe文件在那里,否则请找出它的位置并指向该路径。

现在如果你在VS Code中打开一个新的终端窗口,它应该用bash而不是PowerShell打开。

我只是在打开的终端中键入以下关键字;

powershell bash cmd 节点 Python(或python3)

详见下图。(VSCode版本1.19.1 - windows 10操作系统)

它也适用于VS Code Mac。我尝试用VSCode(版本1.20.1)

只需按Ctrl + Shift +p 搜索“终端:选择默认配置文件”单击 您将看到终端选项并选择Git Bash