我在我的 Windows 10 PC 上使用 Visual Studio Code。我想将我的默认终端从 Windows PowerShell 更改为 Ubuntu(在 Windows 上)上的 Bash。
我怎样才能做到这一点?
https://i.stack.imgur.com/KHWog.png
https://i.imgur.com/wsW4ig2.png
https://i.imgur.com/XXy9VGm.png
通过运行终端配置您的默认集成终端:选择默认配置文件命令,也可以通过终端下拉菜单访问。
https://i.stack.imgur.com/dJNKP.png
请参阅https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles
我只需在打开的终端中输入以下关键字;
powershell bash cmd节点python(或python3)
https://i.stack.imgur.com/3G0t7.png
它也适用于 VS Code Mac。我用VSCode(版本1.20.1)试过了
bash
作为默认 shell 时才有效。
wsl
即可发挥绝对的魅力
转到 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 打开。
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.linux
和 terminal.integrated.defaultProfile.windows
和 terminal.integrated.defaultProfile.osx
。魔法三..
由于您使用 WSL,VSCode 具有专用的 Remote - WSL 扩展,因此您可以直接在 VSCode 中使用 Linux 环境。在 Linux 中打开项目时,默认使用 Linux 默认 shell(默认为 bash),因此无需配置。
如果你想切换到其他配置文件,有终端 > 集成 > 默认配置文件:Linux 部分,所以你可以选择你最喜欢的。
https://i.stack.imgur.com/XUGJW.png
放弃@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”是一个保留名称,我猜你不能设置路径。
如果要选择控制台的类型,可以在文件“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 选项仍然有效,但已被贬值。解决方法是改用集成配置文件:
"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": []
}
}
要在 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
您可以通过按 CTRL SHIFT P
打开命令托盘来更改终端
或者您可以转到顶部的查看并单击“打开命令面板”
然后输入 Terminal: Select Default Profile
然后你输入你想要的终端。
按 ctrl+Shift+p -> 在文件中键入 settings.json 将“powershell”更改为“Git Bash”