【发布时间】:2017-07-08 09:46:58
【问题描述】:
VSCode IDE 可以做到这一点吗? 打开新的集成终端时自动执行命令,例如运行批处理文件或powershell脚本?
【问题讨论】:
标签: visual-studio-code vscode-settings
VSCode IDE 可以做到这一点吗? 打开新的集成终端时自动执行命令,例如运行批处理文件或powershell脚本?
【问题讨论】:
标签: visual-studio-code vscode-settings
是的,您可以使用"terminal.integrated.shellArgs" 设置将参数传递给shell。例如,以下将在打开新终端实例时打印Hello World:
"terminal.integrated.shellArgs.windows": [
"-NoExit", "-Command", "Write-Host Hello World"
]
【讨论】:
terminal.integrated.shell.windows 更改为默认值(PowerShell)以外的其他值.
以前的答案已被弃用,尽管它仍然可以工作,但会发出警告。在 VS Code 中执行此操作的新方法是将此部分添加到您的 settings.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"
}
}
【讨论】: