ChatGPT解决这个技术问题 Extra ChatGPT

VSCode 更改默认终端

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

我怎样才能做到这一点?


L
Levi Fuller

https://i.stack.imgur.com/KHWog.png

https://i.imgur.com/wsW4ig2.png

https://i.imgur.com/XXy9VGm.png


截至今天,在 MacOS 上,终端扩展在菜单中没有“选择默认外壳”选项!幸运的是我使用 stackoverflow.com/a/49916667/99834 工作。
我现在正在使用 MacOS Catalina,“终端:选择默认外壳”在那里并为我工作。
Linux 和 MAC 的更新答案:askubuntu.com/a/1118140/810954
像魅力一样工作。谢谢。
这是否改变了,因为我在 Windows 版本 1.65.2 上完成了此操作,并且每次重新启动时,我都会得到 powershell 而不是 Git bash
a
arielhad

通过运行终端配置您的默认集成终端:选择默认配置文件命令,也可以通过终端下拉菜单访问。

https://i.stack.imgur.com/dJNKP.png

请参阅https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles


这是正确且最新的方法,但是,它在 VS Code v1.56.2 中对我不起作用。这适用于 "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"
当我尝试使用“terminal.integrated.shell.windows”时:“C:\\WINDOWS\\System32\\bash.exe”我收到此警告-“已弃用,新推荐的配置默认 shell 的方法是通过创建终端配置文件”(VS Code v1.56.2)
我得到了同样的弃用警告,但至少它有效。就像我说的推荐方式在 v1.56.2 上对我不起作用。
在 VSCode 1.56.2 中也不适用于我。使用不推荐的方式,它的工作原理。
有一个小的下拉菜单显示 Select Default Profile... 将当前 shell 设置为默认配置文件。
A
AnandShanbhag

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

powershell bash cmd节点python(或python3)

https://i.stack.imgur.com/3G0t7.png

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


似乎仅在选择 bash 作为默认 shell 时才有效。
正在寻找一种在Windows上打开我的wsl而不更改默认值的方法,创建新的,然后将默认值切换回powershell。只需键入 wsl 即可发挥绝对的魅力
H
Herb Caudill

转到 File > Preferences > Settings(或按 Ctrl+,)然后单击右上角最左侧的图标“打开设置 (JSON)”

https://i.stack.imgur.com/xxB1j.png

在 JSON 设置窗口中,添加以下内容(在花括号 {} 内):

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

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

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

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


自此答案以来,VSCode 似乎发生了一些变化,现在有一个带有 {} 的按钮,您必须按下该按钮才能进入编辑器以进行此更改。此答案中的命令确实可以正常工作。谢谢你的回答。
您不应使用 System32 中的可执行文件,因为(通常)vs 代码无权访问该可执行文件。而是使用程序文件一个 terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
"terminal.integrated.shell.windows""terminal.integrated.shell.linux" 已弃用,在我的情况下似乎不起作用(Linux 上的 v1.62.0)。请改用 "terminal.integrated.defaultProfile.windows""terminal.integrated.shell.linux" 并分别在 "terminal.integrated.profiles.windows""terminal.integrated.profiles.linux" 中定义可执行路径。另请参阅下面的@Stephanieraymos 答案。
我有 terminal.integrated.defaultProfile.linuxterminal.integrated.defaultProfile.windowsterminal.integrated.defaultProfile.osx。魔法三..
T
Tan Nguyen

由于您使用 WSL,VSCode 具有专用的 Remote - WSL 扩展,因此您可以直接在 VSCode 中使用 Linux 环境。在 Linux 中打开项目时,默认使用 Linux 默认 shell(默认为 bash),因此无需配置。

如果你想切换到其他配置文件,有终端 > 集成 > 默认配置文件:Linux 部分,所以你可以选择你最喜欢的。

https://i.stack.imgur.com/XUGJW.png


这应该是正确的答案,因为 OP 想在 Vscode 中从 Windows 切换到 Linux,我猜这只有 Remote WSL 才有可能。
我在wsl上将fish设置为默认shell,但是vscode仍然使用bash。明确设置此设置,现在它就像一个魅力,ty!
C
Chuck L

放弃@arielhad 的解决方案......

我的 VSCode 版本是 1.57.1。

打开 settings.xml 文件:

Ctrl + Shift + p

键入“打开设置 (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”是一个保留名称,我猜你不能设置路径。


J
Jhon Stiven Guevara Velasco

如果要选择控制台的类型,可以在文件“keybinding.json”中写入(这个文件可以在以下路径“File->Preferences->Keyboard Shortcuts”中找到)`

//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" 
}`

如果没有这个扩展Shell launcher,这个答案是没有用的。所以只需安装它并指定快捷方式。请注意,此快捷方式已定义 - 找到此快捷方式并检查您是否使用此快捷方式下的操作。
S
Stephanieraymos

集成的 shell 选项仍然有效,但已被贬值。解决方法是改用集成配置文件:

    "terminal.integrated.defaultProfile.windows": "C:\\Program Files\\Git\\bin\\bash.exe (migrated)",
    "terminal.integrated.profiles.windows": {
        "C:\\Program Files\\Git\\bin\\bash.exe (migrated)": {
            "path": "C:\\Program Files\\Git\\bin\\bash.exe",
            "args": []
        }
    }

M
Mustafa Poya

要在 Visual Studio Code 中更改项目的默认终端:

以.vscode的名字创建一个文件夹在这个文件夹中创建一个settings.json文件:写下你想要的设置

例如,如果您是一个窗口用户并且想将 "Command Prompt" 设置为默认终端,您可以编写:

"terminal.integrated.defaultProfile.windows": "Command Prompt"

值 您可以传递:"Git Bash""PowerShell""Command Prompt"

对于 Linux,您将使用 terminal.integrated.defaultProfile.linux,对于 mac os,您将使用:terminal.integrated.defaultProfile.osx

https://i.stack.imgur.com/QEyWZ.png


M
MR Dev

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

或者您可以转到顶部的查看并单击“打开命令面板”

然后输入 Terminal: Select Default Profile

然后你输入你想要的终端。


M
Mohammed Shabeer k

按 ctrl+Shift+p -> 在文件中键入 settings.json 将“powershell”更改为“Git Bash”


大声笑,是什么让这个答案与@OneShadow 的答案不同。请详细说明。