Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: Execute command automatically on WSL terminal opening

I'd like to execute a command automatically every time I open the WSL terminal on Visual Studio Code (Windows 10).

I'm not using the Remote WSL extension, just the WSL terminal with this setting: "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe"

I tried unsuccessfully using terminal.integrated.shellArgs.windows setting.

Is there a way to do it?

like image 577
d79 Avatar asked Apr 14 '26 00:04

d79


1 Answers

You can put in settings.json:

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
    "terminal.integrated.shellArgs.windows": [
        "-e",
        "bash",
        "--rcfile",
        "/path/to/vscode.bashrc"
    ]
}

In vscode.bashrc

source $HOME/.bashrc
your-command

What's in settings.json asks vscode to run following command :

"C:\WINDOWS\System32\wsl.exe" -e bash --rcfile /path/to/vscode.bashrc

-e option of wsl runs "bash --rcfile /path/to/vscode.bashrc"

--rcfile for bash runs /path/to/vscode.bashrc instead of $HOME/.bashrc

For more details, see https://www.gnu.org/software/bash/manual/bash.html

like image 165
Philippe Avatar answered Apr 16 '26 15:04

Philippe