终端启动命令需在settings.json中通过terminal.integrated.profiles.windows(Windows)等系统对应键配置,每个profile含path和args,再由terminal.integrated.defaultProfile.windows指定默认启用项,旧版shell配置已弃用。

终端启动命令在哪配:settings.json 里的 terminal.integrated.profiles.windows(或对应系统键)
VSCode 不在 GUI 设置界面提供“终端启动命令”的直接输入框,所有自定义终端行为都得靠改配置项。Windows 用户找 terminal.integrated.profiles.windows,macOS 对应 terminal.integrated.profiles.osx,Linux 是 terminal.integrated.profiles.linux。这个配置本质是定义一组“终端配置档”,每个档包含 path(可执行文件路径)和可选的 args(启动参数)。你不能只写一条命令,必须把它包装成一个 profile 条目,并通过 terminal.integrated.defaultProfile.windows 指定默认用哪个。
想让终端一打开就执行脚本:用 args 传 -c 或 /c,但要注意 shell 类型
比如你想每次打开终端自动运行 ls -la(macOS/Linux)或 dir(Windows),不能直接把命令塞进 path。正确做法是:
- 对 PowerShell:
args设为["-NoExit", "-Command", "dir"]——-NoExit防止执行完就退出 - 对 CMD:
args设为["/c", "dir && pause"]——/c执行后关闭,加pause才能看见结果 - 对 bash/zsh:
args设为["-c", "ls -la; exec bash"]——exec bash让 shell 继续交互,否则执行完就退出
漏掉 exec 或 -NoExit 是最常见失败原因:终端闪退,你以为配置没生效,其实是命令跑完就关了。
为什么改了配置没反应?检查 profile 名是否匹配 + 默认 profile 是否指向它
很多人只改了 profiles 里新增的条目,却忘了同步设置 defaultProfile。例如你加了一个叫 "MyZsh" 的 profile:
"terminal.integrated.profiles.osx": {
"MyZsh": {
"path": "/bin/zsh",
"args": ["-c", "echo 'hello'; exec zsh"]
}
},
"terminal.integrated.defaultProfile.osx": "MyZsh"
缺了最后一行,VSCode 还是会启动默认的 zsh,完全无视你的 args。另外注意大小写和空格:profile 名必须完全一致,包括引号内外的字符;Windows 下 path 建议用正斜杠或双反斜杠,单反斜杠可能被当成转义符解析出错。
不推荐用 terminal.integrated.shell.*:已弃用且不支持参数
老教程常提 terminal.integrated.shell.windows 和 shellArgs,这两个配置在 VSCode 1.78+ 已被标记为 deprecated,新版中即使写了也不会生效。强行使用会导致终端无法启动,报错信息类似 Unable to resolve shell path。现在唯一可靠路径就是走 profiles + defaultProfile 这套机制。如果你看到插件或文档还在用 shell 配置项,说明它没跟上 VSCode 的演进节奏。
真正麻烦的是跨平台项目:同一份 settings.json 在不同系统下要靠条件覆盖或手动切换 profile 键名;还有某些 shell(如 Windows 的 Windows Terminal)不接受 -c 参数,得换用 --startingDirectory 等原生命令行选项——这些细节不会报错,但命令就是不执行。


















