ChatGPT解决这个技术问题 Extra ChatGPT

VSCode Change Default Terminal

I am using Visual Studio Code on my Windows 10 PC. I want to change my default terminal from Windows PowerShell to Bash on Ubuntu (on Windows).

How can I do that?


L
Levi Fuller

https://i.stack.imgur.com/KHWog.png

https://i.imgur.com/wsW4ig2.png

https://i.imgur.com/XXy9VGm.png


As of today on MacOS the Terminal extension does not have a "Select Default Shell" option in the menu! Lucky for me using stackoverflow.com/a/49916667/99834 worked.
I'm using MacOS Catalina right now, "Terminal: Select Default Shell" was there and worked for me.
Updated Answer for Linux and MAC: askubuntu.com/a/1118140/810954
Worked like a charm . Thanks.
Has this changed because I have done this on Windows version 1.65.2 and every time there is a restart, I get the powershell instead of Git bash
a
arielhad

Configure your default integrated terminal by running the Terminal: Select Default Profile command, which is also accessible via the terminal dropdown.

https://i.stack.imgur.com/dJNKP.png

See https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles


This is the correct and most recent way of doing it, however, it doesn't work for me in VS Code v1.56.2. This works "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"
When im trying to use "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe" Im getting this warning - "This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile" (VS Code v1.56.2)
I’m getting the same deprecated warning but at least it works. Like I said recommended way isn’t working for me on v1.56.2.
Not work for me in VSCode 1.56.2 too. Use deprecated way, it works.
There is a Small drop down that says Select Default Profile... that sets the current shell as the default profile.
A
AnandShanbhag

I just type following keywords in the opened terminal;

powershell bash cmd node python (or python3)

https://i.stack.imgur.com/3G0t7.png

It works on VS Code Mac as well. I tried it with VSCode (Version 1.20.1)


Seems to work only when bash is selected as default shell.
Was searching for a way to open my wsl on windows without changing the default, creating new, then switching default back to powershell. Simply typing wsl works an absolute charm
H
Herb Caudill

Go to File > Preferences > Settings (or press Ctrl+,) then click the leftmost icon in the top right corner, "Open Settings (JSON)"

https://i.stack.imgur.com/xxB1j.png

In the JSON settings window, add this (within the curly braces {}):

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\bash.exe"`

(Here you can put any other custom settings you want as well)

Checkout that path to make sure your bash.exe file is there otherwise find out where it is and point to that path instead.

Now if you open a new terminal window in VS Code, it should open with bash instead of PowerShell.


It appears that VSCode has changed a little since this answer, now there is a button with {} on it that you must press to get to the editor to make this change. The command in this answer did work correctly. Thank you for the answer.
You should not use the executable from System32 since (normally) vs code has no access to that executable. Instead use the program files one terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
"terminal.integrated.shell.windows" or "terminal.integrated.shell.linux" is deprecated and it did not seem to work in my case (v1.62.0 on linux). Use "terminal.integrated.defaultProfile.windows" or "terminal.integrated.shell.linux" instead and define the executable path in the "terminal.integrated.profiles.windows" or "terminal.integrated.profiles.linux", repectively. See also @Stephanieraymos answer below.
I have terminal.integrated.defaultProfile.linux and terminal.integrated.defaultProfile.windows and terminal.integrated.defaultProfile.osx. The magic three..
T
Tan Nguyen

Since you use WSL, VSCode has dedicated Remote - WSL extension so you can use Linux environment directly in VSCode. When you open the project inside Linux, by default, it's use Linux default shell (bash by default), so no config needed.

If you want to switch to other profile, there is Terminal > Integrated > Default Profile: Linux section so you can pick your favorite one.

https://i.stack.imgur.com/XUGJW.png


It should be the correct answer, because the OP wants to switch from Windows to Linux in Vscode which is only possible with Remote WSL I guess.
I set fish as default shell on wsl, but vscode still used bash. Set this setting explicitly and now it works like a charms, ty!
C
Chuck L

Going off of @arielhad's solution...

My VSCode version was 1.57.1.

Open settings.xml file:

Ctrl + Shift + p

Type 'Open Settings (JSON)' and select.

Add the following:

"terminal.integrated.profiles.windows": {
    "PowerShell": {
        "path": [
            "${env:windir}\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
            "${env:windir}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
        ],
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": [
            "-NoLogo",
            "-ExecutionPolicy",
            "Bypass"
        ]
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "icon": "terminal-cmd"
    },

//START: THIS DOES NOT WORK
    "Git Bash": {
        "path": [
            "C:\\Program Files\\Git\\bin\\bash.exe",
        ],
        "source": "Git Bash",
        "icon": "terminal-bash"
    }
// END: THIS DOES NOT WORK

//START: THIS WORKS
    "GitBash": {
        "path": [
            "C:\\Program Files\\Git\\bin\\bash.exe",
        ],
        "icon": "terminal-bash"
    }
// END: THIS WORKS
}

I don't know why the second way works but it does. It appears the 'Git Bash' is a reserved name and I guess you cannot set the path.


J
Jhon Stiven Guevara Velasco

If you want to select the type of console, you can write this in the file "keybinding.json" (this file can be found in the following path "File-> Preferences-> Keyboard Shortcuts") `

//with this you can select what type of console you want
{
    "key": "ctrl+shift+t",
    "command": "shellLauncher.launch"
},

//and this will help you quickly change console
{ 
    "key": "ctrl+shift+j", 
    "command": "workbench.action.terminal.focusNext" 
},
{
    "key": "ctrl+shift+k", 
    "command": "workbench.action.terminal.focusPrevious" 
}`

Without this extension Shell launcher this answer is useless. So just install it and specify shortcut. Be careful, this shortcut is already defined - find this shortcut and check if you use action under this shortcut or not.
S
Stephanieraymos

The integrated shell option still works but has been depreciated. The fix is to use the integrated profile instead:

    "terminal.integrated.defaultProfile.windows": "C:\\Program Files\\Git\\bin\\bash.exe (migrated)",
    "terminal.integrated.profiles.windows": {
        "C:\\Program Files\\Git\\bin\\bash.exe (migrated)": {
            "path": "C:\\Program Files\\Git\\bin\\bash.exe",
            "args": []
        }
    }

M
Mustafa Poya

To change the default terminal for your project in Visual Studio Code:

Create a folder by name of .vscode Create a settings.json file in this folder: Write the settings you want

for example, if you are a window user and want to set "Command Prompt" as the default terminal you can write:

"terminal.integrated.defaultProfile.windows": "Command Prompt"

values You can pass: "Git Bash", "PowerShell", and "Command Prompt".

for Linux you will use terminal.integrated.defaultProfile.linux and for mac os you will use: terminal.integrated.defaultProfile.osx

https://i.stack.imgur.com/QEyWZ.png


M
MR Dev

You can change the terminal by opening command pallete by pressing CTRL SHIFT P

or you can go to View in the top and click "Open Command Pallete"

then type Terminal: Select Default Profile

and you you type which terminal you want.


M
Mohammed Shabeer k

press ctrl+Shift+p -> type settings.json at the of file change the 'powershell' to 'Git Bash'


Lol, what makes this answer different from @OneShadow 's answer. Please elaborate more on it.