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

Bru*_*uce 5 visual-studio-code

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

Jon*_*hel 4

之前的答案已被弃用,尽管它仍然有效,但有警告。在 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"
    }
}
Run Code Online (Sandbox Code Playgroud)