在 VSCode IDE 中打开新的集成终端时自动执行命令



VSCode IDE可以做到这一点吗? 在打开新的集成终端时自动执行批处理文件或 powershell 脚本等命令?

是的,您可以使用"terminal.integrated.shellArgs"设置将参数传递给 shell。例如,打开新的终端实例时,以下内容将打印Hello World

"terminal.integrated.shellArgs.windows": [
"-NoExit", "-Command", "Write-Host Hello World"
]

以前的答案已被弃用,尽管它仍然有效,但有警告。 在VS Code中执行此操作的新方法是将此部分添加到设置.json中。 在这里,我将 PowerShell 配置为自动导入一个模块 posh-git,该模块美化了我的 git 命令提示符。 :)

"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit", "-Command", "Import-Module posh-git"
]
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}

最新更新