VSCode: How to run a command after each terminal open?
On Linux systems you should use:
"terminal.integrated.shellArgs.linux"
On Windows and OSX:
terminal.integrated.shellArgs.windows
and
terminal.integrated.shellArgs.osx
respectively.
If you want to apply shellArgs
setting on a per-workspace basis - you can, despite the fact that documentation says:
The first time you open a workspace which defines any of these settings, VS Code will warn you and subsequently always ignore the values after that
At least version 1.42 of VSCode asks you something like:
"This workspace wants to set
shellArgs
, do you want to allow it?"
See issue 19758
On Linux, if you are using bash
(default for shell in VSCode), there are some subtleties:
will execute the script and close terminal right away. To prevent this you'll have to end the script with"terminal.integrated.shellArgs.linux": ["your_init_script.sh"]
$SHELL
command.
But that way you end up in a subshell. Sometimes it's unacceptable (Read 1) (Read 2).#!/bin/bash echo "init" export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want $SHELL
will leave you in the initial shell, but will not execute the"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
.bashrc
init file. So you may want tosource ~/.bashrc
insideyour_init_script.sh
#!/bin/bash source ~/.bashrc echo "init" export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
- And if you already have
some_init_script.sh
in a repository, and for some reason don't feel like addingsource ~/.bashrc
into it, you can use this:
your_init_script.sh:"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
some_init_script.sh:#!/bin/bash source ~/.bashrc source some_init_script.sh
#!/bin/bash echo "init" export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
Outside of VSCode you can do without creating extra file. Like this
But I could not pass this string intobash --init-file <(echo "source ~/.bashrc; source some_init_script.sh")
terminal.integrated.shellArgs.linux
- it needs to be split into array somehow. And none of the combinations I've tried worked.
Also, you can open terminal at a specific folder:
terminal.integrated.cwd
Change env:
"terminal.integrated.env.linux"
"terminal.integrated.env.windows"
"terminal.integrated.env.osx"
And even change terminal to your liking with
terminal.integrated.shell.linux
terminal.integrated.shell.windows
terminal.integrated.shell.osx
Or
terminal.external.linuxExec
terminal.external.osxExec
terminal.external.windowsExec
You can do the following:
"terminal.integrated.shellArgs.windows": ["start-ssh-agent.cmd"]
Modified from: https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-arguments