How to change the integrated terminal in Visual Studio code - visual-studio-code

I want to change integrated terminal to CMDER i use VS Code on Windows 8.1.
I checked the docs and also preference file, but I am confused
which line to change.
External Terminal
// Customizes which terminal to run on Windows.
"terminal.external.windowsExec": "%COMSPEC%",
// Customizes which terminal application to run on OS X.
"terminal.external.osxExec": "Terminal.app",
// Customizes which terminal to run on Linux.
"terminal.external.linuxExec": "xterm",
Integrated Terminal
// The path of the shell that the terminal uses on Linux.
"terminal.integrated.shell.linux": "sh",
// The command line arguments to use when on the Linux terminal.
"terminal.integrated.shellArgs.linux": [],
// The path of the shell that the terminal uses on OS X.
"terminal.integrated.shell.osx": "sh",
// The command line arguments to use when on the OS X terminal.
"terminal.integrated.shellArgs.osx": [],
// The path of the shell that the terminal uses on Windows. When using shells shipped with Windows (cmd, PowerShell or Bash on Ubuntu), prefer C:\Windows\sysnative over C:\Windows\System32 to use the 64-bit versions.
"terminal.integrated.shell.windows": "C:\\Windows\\system32\\cmd.exe",
// The command line arguments to use when on the Windows terminal.
"terminal.integrated.shellArgs.windows": [],
// Controls the font family of the terminal, this defaults to editor.fontFamily's value.
"terminal.integrated.fontFamily": "",
// Controls whether font ligatures are enabled in the terminal.
"terminal.integrated.fontLigatures": false,
// Controls the font size in pixels of the terminal, this defaults to editor.fontSize's value.
"terminal.integrated.fontSize": 0,
// Controls the line height of the terminal, this number is multipled by the terminal font size to get the actual line-height in pixels.
"terminal.integrated.lineHeight": 1.2,
// Controls whether the terminal cursor blinks.
"terminal.integrated.cursorBlinking": false,
// Controls whether locale variables are set at startup of the terminal, this defaults to true on OS X, false on other platforms.
"terminal.integrated.setLocaleVariables": false,
// A set of command IDs whose keybindings will not be sent to the shell and instead always be handled by Code. This allows the use of keybindings that would normally be consumed by the shell to act the same as when the terminal is not focused, for example ctrl+p to launch Quick Open.
"terminal.integrated.commandsToSkipShell": [
"editor.action.toggleTabFocusMode",
"workbench.action.debug.continue",
"workbench.action.debug.restart",
"workbench.action.debug.run",
"workbench.action.debug.start",
"workbench.action.debug.stop",
"workbench.action.quickOpen",
"workbench.action.showCommands",
"workbench.action.terminal.clear",
"workbench.action.terminal.copySelection",
"workbench.action.terminal.focus",
"workbench.action.terminal.focusNext",
"workbench.action.terminal.focusPrevious",
"workbench.action.terminal.kill",
"workbench.action.terminal.new",
"workbench.action.terminal.paste",
"workbench.action.terminal.runSelectedText",
"workbench.action.terminal.scrollDown",
"workbench.action.terminal.scrollDownPage",
"workbench.action.terminal.scrollToBottom",
"workbench.action.terminal.scrollToTop",
"workbench.action.terminal.scrollUp",
"workbench.action.terminal.scrollUpPage",
"workbench.action.terminal.toggleTerminal"
],

To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:
Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
Add a new "terminal.integrated.shell.windows": "C:\\Bin\\Cmder\\Cmder.exe" setting to the User Settings document on the right if it's not already there. This is so you aren't editing the Default Setting directly, but instead adding to it.
Save the User Settings file.
You can then access it with keys Ctrl+backtick by default.

It is possible to get this working in VS Code and have the Cmder terminal be integrated (not pop up).
To do so:
Create an environment variable "CMDER_ROOT" pointing to your Cmder
directory.
In (Preferences > User Settings) in VS Code add the following settings:
"terminal.integrated.shell.windows": "cmd.exe"
"terminal.integrated.shellArgs.windows": ["/k", "%CMDER_ROOT%\\vendor\\init.bat"]

I know is late but you can quickly accomplish that by just typing Ctrl+Shift+P and then type "default" - it will show an option that says:
Terminal: Select Default Shell
It will then display all the terminals available to you.

From Official Docs
Correctly configuring your shell on Windows is a matter of locating
the right executable and updating the setting. Below is a list of
common shell executables and their default locations.
There is also the convenience command Select Default Shell that can be
accessed through the command palette which can detect and set this for
you.
So you can open a command palette using ctrl+shift+p, use the command Select Default Shell, then it displays all the available command line interfaces, select whatever you want, VS code sets that as default integrated terminal for you automatically.
If you want to set it manually find the location of executable of your cli and open user settings of vscode(ctrl+,) then set
"terminal.integrated.shell.windows":"path/to/executable.exe"
Example for gitbash on windows7:
"terminal.integrated.shell.windows":"C:\\Users\\stldev03\\AppData\\Local\\Programs\\Git\\bin\\bash.exe",

For OP's terminal Cmder there is an integration guide, also hinted in the VS Code docs.
If you want to use VS Code tasks and encounter problems after switch to Cmder, there is an update to #khernand's answer. Copy this into your settings.json file:
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "[cmder_root]" // replace [cmder_root] with your cmder path
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd" // <-- this is the relevant change
// OLD: "%CMDER_ROOT%\\vendor\\init.bat"
],
The invoked file will open Cmder as integrated terminal and switch to cmd for tasks - have a look at the source here. So you can omit configuring a separate terminal in tasks.json to make tasks work.
Starting with VS Code 1.38, there is also "terminal.integrated.automationShell.windows" setting, which lets you set your terminal for tasks globally and avoids issues with Cmder.
"terminal.integrated.automationShell.windows": "cmd.exe"

I was successful via settings > Terminal > Integrated > Shell: Linux
from there I edited the path of the shell to be /bin/zsh from the default /bin/bash
there are also options for OSX and Windows as well
#charlieParker - here's what i'm seeing for available commands in the command pallette

If you want to change the external terminal to the new windows terminal, here's how.

The method explained in the accepted answer has been deprecated, now the new recommended way to configure your default shell is by creating a terminal profile in #terminal.integrated.profiles.windows# and setting its profile name as the default in #terminal.integrated.defaultProfile.windows#.
The old method will currently take priority over the new profiles settings but that will change in the future.
See an example for powershell taken from the docs
{
"terminal.integrated.profiles.windows": {
"My PowerShell": {
"path": "pwsh.exe",
"args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "My PowerShell"
}

change external terminal
windows terminal , which has been mentioned by others, is an alternative of alacrity, which is a terminal (emulator)
As stated in vscode, Cmder is a shell, just like powershell or bash.
"terminal.integrated.profiles.windows": {
"cmder": {
// "path": "F:\\cmder\\Cmder.exe", // 这样会开external terminal
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": ["/K", "F:\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.profiles.linux": { "zsh": { "path": "zsh" }, },
"terminal.integrated.defaultProfile.windows": "PowerShell",
The statment in cmder' repo is misleading
Different shells under a terminal:
If you want to change the external terminal to the new windows terminal, here's how.

Probably it is too late but the below thing worked for me:
Open Settings --> this will open settings.json
type terminal.integrated.windows.shell
Click on {} at the top right corner -- this will open an editor where this setting can be over ridden.
Set the value as terminal.integrated.windows.shell: C:\\Users\\<user_name>\\Softwares\\Git\\bin\\bash.exe
Click Ctrl + S
Try to open new terminal. It should open in bash editor in integrated mode.

Working as of 02-Dec-2021.
In settings.json
{
"go.toolsManagement.autoUpdate":true,
"terminal.integrated.profiles.windows":{
"My Bash":{
"path":"D:\\1. Installed_Software\\Git\\bin\\bash.exe"
}
},
"terminal.integrated.defaultProfile.windows":"My Bash"
}
Reference: https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

Related

How can i put powershell version 5 by default? [duplicate]

How can I start Powershell script as noprofile in Visual Studio Code, I can run the Powershell Ise with noprofile with command PowerShell_Ise -NoProfile . But howcan we do the same for a poershell session in Visual Studio Code.
If you're running PowerShell in the PIC (PowerShell Integrated Console), which is a a special shell that comes with the PowerShell extension:
To turn off profile loading in this special shell, make sure that the
PowerShell: Enable Profile Loading option for the PowerShell extension is unchecked (via File > Preferences > Settings, Ctrl-,).
See the bottom section for how to control which particular PowerShell edition / executable is used in the PIC (PowerShell Integrated Console).
If you're running PowerShell as a general-purpose shell in Visual Studio Code's integrated terminal:
You'll have to modify the default PowerShell shell profile or add a custom profile, with an "args" argument value of [ "-noprofile" ], by direct editing of the JSON file underlying the settings, settings.json (>Preferences: Open Settings (JSON) from the command palette).
The following shows a relevant settings.json excerpt with a modified default PowerShell profile that suppresses profile loading.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [ "-noprofile" ] // suppress profile loading
}, // ...
}
Read on for detailed, general information about shells and terminals in Visual Studio Code.
Overview of shell and terminal settings in Visual Studio Code:
3 different types of shells apply intrinsically:
The default shell for the integrated terminal (the TERMINAL tab of the panel).
Optionally, the automation shell to use for automation tasks (defined in tasks.json) instead of the default integrated-terminal shell.
The default shell for opening an external terminal (> Open New External Terminal); note that on Windows you can specify a shell executable directly, but on Unix-like platforms you must specify a terminal application, which itself then determines the shell to launch - see details below.
With the PowerShell extension installed, yet another shell applies:
The specific PowerShell executable to use for the PIC (PowerShell Integrated Console), which provides tight integration with editing and support for debugging PowerShell code.
These shells:
can all be configured separately
may differ in their default behavior
only some of them allow you to specify startup parameters, such as -NoProfile in your case.
The default shells are:
For the integrated terminal and running tasks:
Windows: PowerShell.
Note that if a PowerShell (Core) 6+ version is found to be installed, it takes precedence over the built-in Windows PowerShell edition.
Unix-like platforms: the user's default shell, as reflected in the SHELL environment variable.
For the external terminal:
Windows: conhost.exe, which launches cmd.exe (Command Prompt)
Unix-like platforms: the host platform's default terminal application, such as Terminal.app on macOS, which itself determines what shell to launch (though, by default, it is also the user's default shell).
Note: On Windows only you may specify a shell (rather than a terminal) executable directly (e.g., bash.exe), in which case it opens in a regular console window (conhost.exe)
The following excerpt from a Settings.json file (> Preferences: Open Settings (JSON)) shows the relevant settings for each (as of VSCode v1.60 / PowerShell Extension v2021.8.2):
In earlier VSCode versions, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings determined the default shell and its startup arguments for the integrated terminal. These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*" properties, and an associated "terminal.integrated.defaultProfile.*" property that contains the name of the profile to use by default, as shown below.
{
// ...
// **General-purpose integrated-terminal shell**.
// Shell *profiles* define the *available* shells for the integrated terminal.
// This property is situationally created automatically, platform-appropriately,
// based on what shells VSCode finds in standard locations on your
// system.
// However, it *need not be present* in a given file - VSCode
// knows about about *standard* profiles *implicitly* when it
// comes to choosing a default shell.
// This example applies to Windows, and shows that Git Bash
// was found on the system.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
// To add custom profiles:
// * In file *paths*, use "\\" or "/" as the path separator.
// * Use an "args" array property to specify start-up arguments, if necessary.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
// Define the *default* shell profile, which serves as the default
// shell in the *integrated terminal* and - except
// if overridden, as shown below - also for *tasks*.
"terminal.integrated.defaultProfile.windows": "PowerShell"
// **Automation-tasks shell**,
// for the tasks defined in "tasks.json" and for debugging:
// This definition is *optional* and *overrides* the default shell configured above.
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// that is, this setting doesn't reference the shell *profiles*.
// * While "args" technically allows you to pass startup arguments,
// tasks will *blindly append* "/d /c <command>" (for "cmd.exe")
// "-Command <command>" (for PowerShell) to these startup arguments,
// which can *break* the overall invocation if the args
// you specify include *commands* to execute, not just *options*.
// Note: "terminal.integrated.automationShell.<platform>" is DEPRECATED.
"terminal.integrated.automationProfile.windows": {
"path": "cmd.exe"
}
// **External-terminal executable**:
// The *terminal program* to use for opening an external terminal window, which itself determines what shell to launch.
// (> Open New External Terminal).
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// * There is NO way to pass startup arguments.
// * This example specifies Windows Terminal (wt.exe).
// * On Windows only, you may also specify a *shell* executable directly,
// which then opens in a regular console window (conhost.exe)
"terminal.external.windowsExec": "wt.exe",
// **PowerShell Integrated Console**:
// Profile loading is *disabled* by default; you can enable it here, but
// note that the PowerShell Integrated Console has its own,
// separate $PROFILE location, which differs from the one in a
// regular console window. If you want to load your regular profile,
// place the following statement in the $PROFILE file of
// the Integrated Console:
// . ($PROFILE -replace '\.VSCode', '.PowerShell')
// (Open the profile file for editing by submitting the following command
// from the Integrated Console:
// code $PROFILE
// )
"powershell.enableProfileLoading": false,
// ...
}
If you want to configure the PIC (PowerShell Integrated Console) to use a different PowerShell edition / version:
Note: Written as of version v2022.6.3 of the PowerShell extension.
GUI method:
Make sure that a PowerShell source-code file is the active editor.
Click on {} in the status bar (the bottom right corner), then click on Show PowerShell Session Menu in the tooltip window that pops up, as shown below.
Alternatively, irrespective of whether the active editor contains PowerShell source code or not, submit PowerShell: Show Session Menu in the command palette to open the relevant menu.
)
If the session menu is pinned as an icon (use the pushpin icon on the right edge of the tooltip window to toggle), it looks something like this, reflecting the active version number, and clicking it directly opens the PowerShell session menu in the command palette:
)
This opens the PowerShell session menu in the command palette: Choose from the other available versions, if any, which are prefixed with Switch to:, which makes that version the default going forward.
If the version / edition of interest isn't shown, you must add its executable path either via the Settings GUI - by selecting Modify list of additional PowerShell locations from the PowerShell session menu - or via your settings.json file (see next section).
Via settings.json (> Preferences: Open Settings (JSON)):
The powershell.powerShellAdditionalExePaths setting is a single object that allows you to add the full executable paths of PowerShell versions that the extension couldn't find automatically by self-chosen property names - see example below.
The powershell.powerShellDefaultVersion property determines which version to use by default, which is either the name of property of the powershell.powerShellAdditionalExePaths setting or that of an auto-discovered version, as shown in the session menu. Selecting a Switch to: entry from the menu automatically updates this setting.
{
// ...
// The paths to any PowerShell executables that the extension cannot auto-discover.
// The property names are self-chosen names, which show in the
// PowerShell session menu.
// Note:
// * Executable paths only are supported, not also arguments.
// * If a value isn't a valid executable path, it is ignored,
// and the version doesn't show up in the session menu.
// In the status bar, the currently active version is displayed by its actual characteristics,
// not by these self-chosen property names; e.g.,
// "PowerShell 7.2")
"powershell.powerShellAdditionalExePaths": {
"Latest Preview": "C:\\Users\\jdoe\\AppData\\Local\\Microsoft\\powershell\\pwsh.exe"
},
// The PowerShell version to use by default, which can be
// a property name from "powershell.powerShellAdditionalExePaths" or
// the name of an auto-discovered version, as show in the PowerShell
// session menu.
"powershell.powerShellDefaultVersion": "Latest Preview",
// ...
}
You can go in powershell extension settings and remove check box at "PowerShell: Enable Profile Loading", i think it help. Also check task for runs powershell scripts with some parameters discussion about task

How to fix "Try the new cross-platform Powershell https://aka.ms/pscore6"? [duplicate]

How can I start Powershell script as noprofile in Visual Studio Code, I can run the Powershell Ise with noprofile with command PowerShell_Ise -NoProfile . But howcan we do the same for a poershell session in Visual Studio Code.
If you're running PowerShell in the PIC (PowerShell Integrated Console), which is a a special shell that comes with the PowerShell extension:
To turn off profile loading in this special shell, make sure that the
PowerShell: Enable Profile Loading option for the PowerShell extension is unchecked (via File > Preferences > Settings, Ctrl-,).
See the bottom section for how to control which particular PowerShell edition / executable is used in the PIC (PowerShell Integrated Console).
If you're running PowerShell as a general-purpose shell in Visual Studio Code's integrated terminal:
You'll have to modify the default PowerShell shell profile or add a custom profile, with an "args" argument value of [ "-noprofile" ], by direct editing of the JSON file underlying the settings, settings.json (>Preferences: Open Settings (JSON) from the command palette).
The following shows a relevant settings.json excerpt with a modified default PowerShell profile that suppresses profile loading.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [ "-noprofile" ] // suppress profile loading
}, // ...
}
Read on for detailed, general information about shells and terminals in Visual Studio Code.
Overview of shell and terminal settings in Visual Studio Code:
3 different types of shells apply intrinsically:
The default shell for the integrated terminal (the TERMINAL tab of the panel).
Optionally, the automation shell to use for automation tasks (defined in tasks.json) instead of the default integrated-terminal shell.
The default shell for opening an external terminal (> Open New External Terminal); note that on Windows you can specify a shell executable directly, but on Unix-like platforms you must specify a terminal application, which itself then determines the shell to launch - see details below.
With the PowerShell extension installed, yet another shell applies:
The specific PowerShell executable to use for the PIC (PowerShell Integrated Console), which provides tight integration with editing and support for debugging PowerShell code.
These shells:
can all be configured separately
may differ in their default behavior
only some of them allow you to specify startup parameters, such as -NoProfile in your case.
The default shells are:
For the integrated terminal and running tasks:
Windows: PowerShell.
Note that if a PowerShell (Core) 6+ version is found to be installed, it takes precedence over the built-in Windows PowerShell edition.
Unix-like platforms: the user's default shell, as reflected in the SHELL environment variable.
For the external terminal:
Windows: conhost.exe, which launches cmd.exe (Command Prompt)
Unix-like platforms: the host platform's default terminal application, such as Terminal.app on macOS, which itself determines what shell to launch (though, by default, it is also the user's default shell).
Note: On Windows only you may specify a shell (rather than a terminal) executable directly (e.g., bash.exe), in which case it opens in a regular console window (conhost.exe)
The following excerpt from a Settings.json file (> Preferences: Open Settings (JSON)) shows the relevant settings for each (as of VSCode v1.60 / PowerShell Extension v2021.8.2):
In earlier VSCode versions, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings determined the default shell and its startup arguments for the integrated terminal. These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*" properties, and an associated "terminal.integrated.defaultProfile.*" property that contains the name of the profile to use by default, as shown below.
{
// ...
// **General-purpose integrated-terminal shell**.
// Shell *profiles* define the *available* shells for the integrated terminal.
// This property is situationally created automatically, platform-appropriately,
// based on what shells VSCode finds in standard locations on your
// system.
// However, it *need not be present* in a given file - VSCode
// knows about about *standard* profiles *implicitly* when it
// comes to choosing a default shell.
// This example applies to Windows, and shows that Git Bash
// was found on the system.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
// To add custom profiles:
// * In file *paths*, use "\\" or "/" as the path separator.
// * Use an "args" array property to specify start-up arguments, if necessary.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
// Define the *default* shell profile, which serves as the default
// shell in the *integrated terminal* and - except
// if overridden, as shown below - also for *tasks*.
"terminal.integrated.defaultProfile.windows": "PowerShell"
// **Automation-tasks shell**,
// for the tasks defined in "tasks.json" and for debugging:
// This definition is *optional* and *overrides* the default shell configured above.
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// that is, this setting doesn't reference the shell *profiles*.
// * While "args" technically allows you to pass startup arguments,
// tasks will *blindly append* "/d /c <command>" (for "cmd.exe")
// "-Command <command>" (for PowerShell) to these startup arguments,
// which can *break* the overall invocation if the args
// you specify include *commands* to execute, not just *options*.
// Note: "terminal.integrated.automationShell.<platform>" is DEPRECATED.
"terminal.integrated.automationProfile.windows": {
"path": "cmd.exe"
}
// **External-terminal executable**:
// The *terminal program* to use for opening an external terminal window, which itself determines what shell to launch.
// (> Open New External Terminal).
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// * There is NO way to pass startup arguments.
// * This example specifies Windows Terminal (wt.exe).
// * On Windows only, you may also specify a *shell* executable directly,
// which then opens in a regular console window (conhost.exe)
"terminal.external.windowsExec": "wt.exe",
// **PowerShell Integrated Console**:
// Profile loading is *disabled* by default; you can enable it here, but
// note that the PowerShell Integrated Console has its own,
// separate $PROFILE location, which differs from the one in a
// regular console window. If you want to load your regular profile,
// place the following statement in the $PROFILE file of
// the Integrated Console:
// . ($PROFILE -replace '\.VSCode', '.PowerShell')
// (Open the profile file for editing by submitting the following command
// from the Integrated Console:
// code $PROFILE
// )
"powershell.enableProfileLoading": false,
// ...
}
If you want to configure the PIC (PowerShell Integrated Console) to use a different PowerShell edition / version:
Note: Written as of version v2022.6.3 of the PowerShell extension.
GUI method:
Make sure that a PowerShell source-code file is the active editor.
Click on {} in the status bar (the bottom right corner), then click on Show PowerShell Session Menu in the tooltip window that pops up, as shown below.
Alternatively, irrespective of whether the active editor contains PowerShell source code or not, submit PowerShell: Show Session Menu in the command palette to open the relevant menu.
)
If the session menu is pinned as an icon (use the pushpin icon on the right edge of the tooltip window to toggle), it looks something like this, reflecting the active version number, and clicking it directly opens the PowerShell session menu in the command palette:
)
This opens the PowerShell session menu in the command palette: Choose from the other available versions, if any, which are prefixed with Switch to:, which makes that version the default going forward.
If the version / edition of interest isn't shown, you must add its executable path either via the Settings GUI - by selecting Modify list of additional PowerShell locations from the PowerShell session menu - or via your settings.json file (see next section).
Via settings.json (> Preferences: Open Settings (JSON)):
The powershell.powerShellAdditionalExePaths setting is a single object that allows you to add the full executable paths of PowerShell versions that the extension couldn't find automatically by self-chosen property names - see example below.
The powershell.powerShellDefaultVersion property determines which version to use by default, which is either the name of property of the powershell.powerShellAdditionalExePaths setting or that of an auto-discovered version, as shown in the session menu. Selecting a Switch to: entry from the menu automatically updates this setting.
{
// ...
// The paths to any PowerShell executables that the extension cannot auto-discover.
// The property names are self-chosen names, which show in the
// PowerShell session menu.
// Note:
// * Executable paths only are supported, not also arguments.
// * If a value isn't a valid executable path, it is ignored,
// and the version doesn't show up in the session menu.
// In the status bar, the currently active version is displayed by its actual characteristics,
// not by these self-chosen property names; e.g.,
// "PowerShell 7.2")
"powershell.powerShellAdditionalExePaths": {
"Latest Preview": "C:\\Users\\jdoe\\AppData\\Local\\Microsoft\\powershell\\pwsh.exe"
},
// The PowerShell version to use by default, which can be
// a property name from "powershell.powerShellAdditionalExePaths" or
// the name of an auto-discovered version, as show in the PowerShell
// session menu.
"powershell.powerShellDefaultVersion": "Latest Preview",
// ...
}
You can go in powershell extension settings and remove check box at "PowerShell: Enable Profile Loading", i think it help. Also check task for runs powershell scripts with some parameters discussion about task

How can I start Powershell script as noprofile in Visual Studio Code

How can I start Powershell script as noprofile in Visual Studio Code, I can run the Powershell Ise with noprofile with command PowerShell_Ise -NoProfile . But howcan we do the same for a poershell session in Visual Studio Code.
If you're running PowerShell in the PIC (PowerShell Integrated Console), which is a a special shell that comes with the PowerShell extension:
To turn off profile loading in this special shell, make sure that the
PowerShell: Enable Profile Loading option for the PowerShell extension is unchecked (via File > Preferences > Settings, Ctrl-,).
See the bottom section for how to control which particular PowerShell edition / executable is used in the PIC (PowerShell Integrated Console).
If you're running PowerShell as a general-purpose shell in Visual Studio Code's integrated terminal:
You'll have to modify the default PowerShell shell profile or add a custom profile, with an "args" argument value of [ "-noprofile" ], by direct editing of the JSON file underlying the settings, settings.json (>Preferences: Open Settings (JSON) from the command palette).
The following shows a relevant settings.json excerpt with a modified default PowerShell profile that suppresses profile loading.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [ "-noprofile" ] // suppress profile loading
}, // ...
}
Read on for detailed, general information about shells and terminals in Visual Studio Code.
Overview of shell and terminal settings in Visual Studio Code:
3 different types of shells apply intrinsically:
The default shell for the integrated terminal (the TERMINAL tab of the panel).
Optionally, the automation shell to use for automation tasks (defined in tasks.json) instead of the default integrated-terminal shell.
The default shell for opening an external terminal (> Open New External Terminal); note that on Windows you can specify a shell executable directly, but on Unix-like platforms you must specify a terminal application, which itself then determines the shell to launch - see details below.
With the PowerShell extension installed, yet another shell applies:
The specific PowerShell executable to use for the PIC (PowerShell Integrated Console), which provides tight integration with editing and support for debugging PowerShell code.
These shells:
can all be configured separately
may differ in their default behavior
only some of them allow you to specify startup parameters, such as -NoProfile in your case.
The default shells are:
For the integrated terminal and running tasks:
Windows: PowerShell.
Note that if a PowerShell (Core) 6+ version is found to be installed, it takes precedence over the built-in Windows PowerShell edition.
Unix-like platforms: the user's default shell, as reflected in the SHELL environment variable.
For the external terminal:
Windows: conhost.exe, which launches cmd.exe (Command Prompt)
Unix-like platforms: the host platform's default terminal application, such as Terminal.app on macOS, which itself determines what shell to launch (though, by default, it is also the user's default shell).
Note: On Windows only you may specify a shell (rather than a terminal) executable directly (e.g., bash.exe), in which case it opens in a regular console window (conhost.exe)
The following excerpt from a Settings.json file (> Preferences: Open Settings (JSON)) shows the relevant settings for each (as of VSCode v1.60 / PowerShell Extension v2021.8.2):
In earlier VSCode versions, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings determined the default shell and its startup arguments for the integrated terminal. These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*" properties, and an associated "terminal.integrated.defaultProfile.*" property that contains the name of the profile to use by default, as shown below.
{
// ...
// **General-purpose integrated-terminal shell**.
// Shell *profiles* define the *available* shells for the integrated terminal.
// This property is situationally created automatically, platform-appropriately,
// based on what shells VSCode finds in standard locations on your
// system.
// However, it *need not be present* in a given file - VSCode
// knows about about *standard* profiles *implicitly* when it
// comes to choosing a default shell.
// This example applies to Windows, and shows that Git Bash
// was found on the system.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
// To add custom profiles:
// * In file *paths*, use "\\" or "/" as the path separator.
// * Use an "args" array property to specify start-up arguments, if necessary.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
// Define the *default* shell profile, which serves as the default
// shell in the *integrated terminal* and - except
// if overridden, as shown below - also for *tasks*.
"terminal.integrated.defaultProfile.windows": "PowerShell"
// **Automation-tasks shell**,
// for the tasks defined in "tasks.json" and for debugging:
// This definition is *optional* and *overrides* the default shell configured above.
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// that is, this setting doesn't reference the shell *profiles*.
// * While "args" technically allows you to pass startup arguments,
// tasks will *blindly append* "/d /c <command>" (for "cmd.exe")
// "-Command <command>" (for PowerShell) to these startup arguments,
// which can *break* the overall invocation if the args
// you specify include *commands* to execute, not just *options*.
// Note: "terminal.integrated.automationShell.<platform>" is DEPRECATED.
"terminal.integrated.automationProfile.windows": {
"path": "cmd.exe"
}
// **External-terminal executable**:
// The *terminal program* to use for opening an external terminal window, which itself determines what shell to launch.
// (> Open New External Terminal).
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// * There is NO way to pass startup arguments.
// * This example specifies Windows Terminal (wt.exe).
// * On Windows only, you may also specify a *shell* executable directly,
// which then opens in a regular console window (conhost.exe)
"terminal.external.windowsExec": "wt.exe",
// **PowerShell Integrated Console**:
// Profile loading is *disabled* by default; you can enable it here, but
// note that the PowerShell Integrated Console has its own,
// separate $PROFILE location, which differs from the one in a
// regular console window. If you want to load your regular profile,
// place the following statement in the $PROFILE file of
// the Integrated Console:
// . ($PROFILE -replace '\.VSCode', '.PowerShell')
// (Open the profile file for editing by submitting the following command
// from the Integrated Console:
// code $PROFILE
// )
"powershell.enableProfileLoading": false,
// ...
}
If you want to configure the PIC (PowerShell Integrated Console) to use a different PowerShell edition / version:
Note: Written as of version v2022.6.3 of the PowerShell extension.
GUI method:
Make sure that a PowerShell source-code file is the active editor.
Click on {} in the status bar (the bottom right corner), then click on Show PowerShell Session Menu in the tooltip window that pops up, as shown below.
Alternatively, irrespective of whether the active editor contains PowerShell source code or not, submit PowerShell: Show Session Menu in the command palette to open the relevant menu.
)
If the session menu is pinned as an icon (use the pushpin icon on the right edge of the tooltip window to toggle), it looks something like this, reflecting the active version number, and clicking it directly opens the PowerShell session menu in the command palette:
)
This opens the PowerShell session menu in the command palette: Choose from the other available versions, if any, which are prefixed with Switch to:, which makes that version the default going forward.
If the version / edition of interest isn't shown, you must add its executable path either via the Settings GUI - by selecting Modify list of additional PowerShell locations from the PowerShell session menu - or via your settings.json file (see next section).
Via settings.json (> Preferences: Open Settings (JSON)):
The powershell.powerShellAdditionalExePaths setting is a single object that allows you to add the full executable paths of PowerShell versions that the extension couldn't find automatically by self-chosen property names - see example below.
The powershell.powerShellDefaultVersion property determines which version to use by default, which is either the name of property of the powershell.powerShellAdditionalExePaths setting or that of an auto-discovered version, as shown in the session menu. Selecting a Switch to: entry from the menu automatically updates this setting.
{
// ...
// The paths to any PowerShell executables that the extension cannot auto-discover.
// The property names are self-chosen names, which show in the
// PowerShell session menu.
// Note:
// * Executable paths only are supported, not also arguments.
// * If a value isn't a valid executable path, it is ignored,
// and the version doesn't show up in the session menu.
// In the status bar, the currently active version is displayed by its actual characteristics,
// not by these self-chosen property names; e.g.,
// "PowerShell 7.2")
"powershell.powerShellAdditionalExePaths": {
"Latest Preview": "C:\\Users\\jdoe\\AppData\\Local\\Microsoft\\powershell\\pwsh.exe"
},
// The PowerShell version to use by default, which can be
// a property name from "powershell.powerShellAdditionalExePaths" or
// the name of an auto-discovered version, as show in the PowerShell
// session menu.
"powershell.powerShellDefaultVersion": "Latest Preview",
// ...
}
You can go in powershell extension settings and remove check box at "PowerShell: Enable Profile Loading", i think it help. Also check task for runs powershell scripts with some parameters discussion about task

How to add anaconda powershell to vscode?

I'm trying to add anaconda prompt to start up instead of powershell to avoid having to add python to env variables.
"terminal.integrated.shellArgs.windows": [
<args>
]
I tried putting them into single line, splitting them "-Foo Goo" as well as "-Foo","Goo". Each version leads to either error or simply ignoring the "-Command" parameter (the lines simply get pasted, but not executed).
First of all, I I'd like to give a hint for everyone that uses PowerShell to use the new one.
So, with the Anaconda ready to go (and it been equal or greater than 4.6 - use conda --version) run in sequence (from base environment in cwd terminal):
conda update conda
conda init
This will update your conda root environment and the init will setup all you need to run it on both cwd and powershell.
After this, you can start any powershell (inside vscode or not) and it will be conda ready.
Look at this article for further information.
Hope it helps!
I ended up using this (although it has tendency to break).
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy"
, "ByPass"
, "-NoExit"
, "-Command"
, "& 'C:\\ProgramData\\Anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Anaconda3'"
],
Thanks Zerg! Your answer worked for me but I also got a warning message to say that this approach has been depreciated. After some googling I got this working by adding a new terminal profile to settings.json.
"terminal.integrated.profiles.windows": {
"PowerShell (Anaconda)": {
"source": "PowerShell",
"args": [
"-ExecutionPolicy"
, "ByPass"
, "-NoExit"
, "-Command"
, "& 'C:\\Users\\<username>\\AppData\\Local\\Continuum\\anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Users\\<username>\\AppData\\Local\\Continuum\\anaconda3'"
]
}
},
Then changing the default profile:
"terminal.integrated.defaultProfile.windows": "PowerShell (Anaconda)",
I just installed PowerShell 7, and since I had anaconda installed before, this seems to add the starting command to the profile.ps1 automatically.
The profile.ps1 in C:\Users\USER\Documents\PowerShell (this is version 7, directory WindowsPowerShell would be the old version 5) contains:
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "C:\Users\USER\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
With these automatic settings at the start of PowerShell 7, adding PowerShell 7 as a new terminal type to vsccode solved it.
This is how to add PowerShell 7 to the dropdown menu:
Enter Ctrl+Shift+P, open settings.json for the User, and add
{
"terminal.integrated.profiles.windows": {
"PowerShell7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": ["-NoProfile",
"-noexit",
"-file",
"C:\\Users\\USER\\Documents\\PowerShell\\profile.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell7"
}
Then in the settings.json, press Ctrl+s and restart (!) vscode. You will see PowerShell7 as the new default terminal in the dropdown of terminal types:
From the VSCode Command Palette (Ctrl+Shift+P), select
Terminal: Select default shell
and then pick PowerShell.
Then from the Command Palette (Ctrl+Shift+P), select
Python: Select Interpreter
and pick one of the conda environments. When you now open a new terminal VSCode starts PowerShell and activates the selected environment. This is exactly what the Anaconda-Prompt does. However, you should not set a PYTHONPATH in the environment in combination with an Anaconda install. Conda activation is all you need. It not only adds the selected interpreter to the PATH, but the required libraries too.

How to clear the entire terminal (PowerShell)

I had an issue. Using the clear or cls command in powershell clears only the visible portion of the terminal,I would like to know how to clear the entire terminal?
I use VSCode by the way.
To also clear the scrollback buffer, not just the visible portion of the terminal in Visual Studio Code's integrated terminal, use one of the following methods:
Use the command palette:
Press Ctrl+Shift+P and type tclear to match the Terminal: Clear command and press Enter
Use the integrated terminal's context menu:
Right-click in the terminal and select Clear from the context menu.
On Windows, you may have to enable the integrated terminal's context menu first, given that by default right-clicking pastes text from the clipboard:
Open the settings (Ctrl+,) and change setting terminal.integrated.rightClickBehavior to either default or selectWord (the latter selects the word under the cursor before showing the context menu).
Use a keyboard shortcut from inside the integrated terminal (current as of v1.71 of VSCode):
On macOS, a shortcut exists by default: Cmd+K
On Linux and Windows, you can define an analogous custom key binding, Ctrl+K, as follows, by directly editing file keybindings.json (command Preferences: Open Keyboard Shortcuts (JSON) from the command palette), and placing the following object inside the existing array ([ ... ]):
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus && terminalHasBeenCreated || terminalFocus && terminalProcessSupported"
}
Using a command you can invoke from a shell in the integrated terminal:
Note: A truly cross-platform solution would require executing the VSCode-internal workbench.action.terminal.clear command from a shell, but I don't know how to do that / if it is possible at all - do tell us if you know.
Linux (at least as observed on Ubuntu):
Use the standard clear utility (/usr/bin/clear), which also clears the scrollback buffer.
From PowerShell, you may also use Clear-Host or its built-in alias, cls.
By contrast, [Console]::Clear() does NOT clear the scrollback buffer and clear just one screenful.
macOS:
Unfortunately, neither /usr/bin/clear nor PowerShell's Clear-Host (cls) nor .NET's [Console]::Clear() clear the scrollback buffer - they all clear just one screenful.
Print the following ANSI control sequence: '\e[2J\e[3J\e[H' (\e represents the ESC char. (0x1b, 27); e.g., from bash: printf '\e[2J\e[3J\e[H'; from PowerShell: "`e[2J`e[3J`e[H"
You can easily wrap this call in a shell script for use from any shell: create a file named, say, cclear, in a directory listed in your system's PATH variable, then make it executable with chmod a+x; then save the following content to it:
#!/bin/bash
# Clears the terminal screen *and the scrollback buffer*.
# (Needed only on macOS, where /usr/bin/clear doesn't do the latter.)
printf '\e[2J\e[3J\e[H'
Windows:
NO solution that I'm aware of: cmd.exe's internal cls command and PowerShell's internal Clear-Host command clear only one screenful in the integrated terminal (not also the scrollback buffer - even though they also do the latter in a regular console window and in Windows Terminal).
Unfortunately, the escape sequence that works on macOS ("`e[2J`e[3J`e[H" or, for Windows PowerShell, "$([char]27)[2J$([char]27)[3J$([char]27)[H") is not effective: on Windows it just clears one screenful.
(By contrast, all of these methods do also clear the scrollback buffer in regular console windows and Windows Terminal.)
right click on the powershell button,
then select clear,
when you are at the command window, type "clear" command, to clear the terminal window.