Automatically Execute a command when opening a new Integrated Terminal in VSCode IDE

Viewed 4005

Can VSCode IDE do this? Execute a command such as running a batch file or powershell script automatically when a new Integrated Terminal is opened?

2 Answers

The previous answer was deprecated although it will still work but with a warning. The new way to do it in VS Code is to add this section to your settings.json. Here I configured my PowerShell to automatically import a module posh-git that prettifies my command prompt for 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"
    }
}
Related