Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I detect in Powershell that I am running in VS Code's integrated terminal?

I would like to modify the standard PowerShell profile in Windows if the Powershell opens inside VS Code integrated terminal (when you are editing e.g. python scripts in VS Code, rather than PS scripts, which opens the ISE profile in any case).

Is there some environmental variable that gets set by the integrated PowerShell? Or is there some way of opening Powershell with a particular profile, instead of the default?

Thanks

like image 227
wigster Avatar asked Sep 04 '19 12:09

wigster


People also ask

Is VS Code terminal PowerShell?

PowerShell TerminalIf you are running VS Code on Linux, your default terminal will be Bash. To change to PowerShell, you can modify the Terminal Settings by clicking the drop down in the Terminal and clicking Configure Terminal Settings.

What is PowerShell integrated console?

By contrast, the PowerShell Integrated Console is a special shell that comes with the PowerShell extension and offers integration with PowerShell code being edited, notably to provide linting and debugging support, among other features.


1 Answers

VS Code creates an environment variable named TERM_PROGRAM. You can check it for a value of vscode, something like this:

if($env:TERM_PROGRAM -eq 'vscode') {
  # do some stuff...
}
like image 89
aphoria Avatar answered Oct 07 '22 12:10

aphoria