Nick Wills
Nick Wills

Reputation: 1138

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

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?

Upvotes: 6

Views: 7916

Answers (2)

Jon Burchel
Jon Burchel

Reputation: 173

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"
    }
}

Upvotes: 4

Gama11
Gama11

Reputation: 34138

Yes, you can use the "terminal.integrated.shellArgs" setting to pass arguments to the shell. For instance, the following will print Hello World when opening a new Terminal instance:

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

Upvotes: 4

Related Questions