有关 Visual Studio Code 中使用的所有类型的 shell 的概述,请参阅 此答案。
自定义 shell 配置文件存储在settings.json
文件中;要打开它进行编辑,请从命令面板 (Ctrl-Shift-P) 中选择 Preferences: Open Settings (JSON)
。
有特定于平台的属性,名称为 terminal.integrated.profiles.*
,其中 *
是 windows
、linux
或 osx
(macOS)。
每个内部的属性都定义了shell 配置文件,即通过下拉菜单标记为 +
()在集成终端中可用于运行的shell。
每个shell 配置文件定义:
最少需要一个path
参数来指定shell可执行文件的完整路径,或者仅在Windows上,一个source
参数,可以是PowerShell
或Git Bash
,以便让VS Code找到适当的可执行文件。
启动参数通过args
指定。
有关所有支持的属性,请参见文档。
要设置默认的shell配置文件:
方法一:在命令面板中使用Terminal: Select Default Profile
命令,然后会显示所有已定义的配置文件列表,选择所需的配置文件。
方法二:将适用于平台的terminal.integrated.defaultProfile.*
属性设置为所需 shell 配置文件的名称。
示例:在 Windows 上将 Node.js(node.exe
)定义为自定义 shell 配置文件:
node.exe
的完整路径,并通过将其加倍来转义 JSON 中的 \
字符;例如,从 PowerShell 中:# Get node.exe's full path, escape '\' chars., copy to the clipboard.
(Get-Command node.exe).Path.Replace('\', '\\') | Set-Clipboard
settings.json
文件中(如果terminal.integrated.profiles.windows
属性已经存在,则只需将Node.js
属性添加到其中);示例使用node.exe
的默认安装位置C:\Program Files\nodejs\node.exe
。"terminal.integrated.profiles.windows": {
"Node.js": {
"path": "C:\\Program Files\\nodejs\\node.exe",
"args": [] // Add startup arguments as needed.
}
},
// Make Node.js the default shell (if the property already exists, update its value).
"terminal.integrated.defaultProfile.windows": "Node.js",
// 将Node.js设置为默认shell(如果该属性已存在,则更新其值)。 "terminal.integrated.defaultProfile.windows": "Node.js",
} - Milán Nikolics