Use cmder as default shell in VSCode - visual-studio-code

Every other solution I can find to this question says to put the settings below inside my.vscode/settings.json
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/K",
"C:\\softwares\\cmder\\vendor\\init.bat"
],
This worked until recently, when I removed my settings file from a git repo. Now when I hover over the code above, I get this text in a popup
The path of the shell that the terminal uses on Windows (default:
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe). Read more
about configuring the shell. This is deprecated, use
#terminal.integrated.defaultProfile.windows# instead(2)
This is a bit confusing to me, I'm not sure what I have to change to what. I tried changing the first setting to
"terminal.integrated.defaultProfile.windows": "C:\\WINDOWS\\System32\\cmd.exe",
But this has had no effect. Cmder is not being used as the default shell.

VSCode changed how integrated terminal profiles are handled in April 2021. Based on the args you provided in your question, adding this to your settings.json should work:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"C:\\softwares\\cmder\\vendor\\init.bat"
],
"icon": "terminal-cmd"
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt"

cmder comes as an executable program. You do not need to use a batch script to open it. Just firing the exe starts the program.
(from the official download page:)
Unzip
(optional) Place your own executable files into the bin folder to be injected into
your PATH.
Run Cmder (Cmder.exe)
Therefore, you just need to add a single line to settings.json:
"terminal.integrated.shell.windows": "C:\\full\\path\\to\\unzipped\\cmder.exe"
This shouldn't need to take in any flags or commands, args, unless you are wanting to change it's default functionalities (such as changing the default folder that the cursor points to on launch). For default cmder, just run the exe...

try add follow config in settings.json
"terminal.integrated.automationShell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
A path that when set will override terminal.integrated.shell.windows and ignore shellArgs values for automation-related terminal usage like tasks and debug.

Related

Can you get Warp terminal as the integrated terminal in VS Code?

I followed the directions on Warp's documentation, but this only replaces the external terminal (it opens as a separate window).
https://www.warp.dev/blog/how-to-open-warp-vscode
I would like Warp to replace vscode's usage of xterm in the integrated terminal, but I can't seem to figure out how to do that.
My attempt was to edit the profiles in my settings.json:
"terminal.integrated.profiles.osx": {
"bash": {
"path": "bash",
"args": [
"-l"
],
"icon": "terminal-bash"
},
"zsh": {
"path": "zsh",
"args": [
"-l"
]
},
"fish": {
"path": "fish",
"args": [
"-l"
]
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
},
"warp": {
"path": "/Applications/Warp.app/Contents/MacOS/stable",
"icon": "/Applications/Warp.app/Contents/Resources/Warp.icns"
}
},
"terminal.integrated.defaultProfile.osx": "warp",
but all this did was open up Warp in a separate window and the existing integrated terminal contained the output logs of Warp.
The Warp documentation doesn't include changing the integrated terminal and neither does the vscode documentation, so I highly suspect this is not feasible, but I was wondering if there was some less obvious workaround that someone might have found.
I guess that there's a misunderstanding of the terms
'warp' is a terminal emulator application
but VSCode integrates command shells like bash, zsh, etc.
terminal apps in most cases it's GUI apps that allow you to work with a command shell. In this case VSCode's terminal window it's a terminal app. that's why you can't just use 'warp' or any other GUI terminal emulator inside the VSCode environment.
It seems that Warp can't be accepted by vscode as the default integrated terminal.
Value is not accepted. Valid values: null, "bash", "csh", "dash",
"ksh", "sh", "tcsh", "zsh", "JavaScript Debug Terminal".
Once Warp starts building to WASM (looks like they're working on Windows, Linux, and WASM support), it might be embeddable into VS Code and/or Theia as a WebView Extension
Replacing the vscode integrated terminal is a feature in the warp team's backlog, but one of the engineers says:
"This is really really difficult eng wise. Just being transparent so people don't get their hopes up that this would come out anytime soon."
https://github.com/warpdotdev/Warp/issues/257#issuecomment-1274198741

How to run streamlit multi-command in VS Code regardless of default terminal

I have the Multi-command extension installed on VS Code and use it to launch Streamlit apps using this configuration in settings.json which is run via a keyboard shortcut:
"multiCommand.commands": [
{
"command": "multiCommand.streamlitActiveFile",
"label": "Streamlit: Run Active File",
"description": "Streamlit run active file in active terminal",
"sequence": [
"workbench.action.terminal.focus",
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "streamlit run ${relativeFile}\u000D"
}
}
]
}
]
This has worked fine thus far while I have been using the standard command prompt on a Windows machine. Now I've changed to using Git Bash as my default terminal, and the command above fails because the relative file path is passed as a Windows path with backslashes, and Git Bash can't parse that:
$ streamlit run visuals\streamlit\time_plot.py
Usage: streamlit run [OPTIONS] TARGET [ARGS]...
Try 'streamlit run --help' for help.
Error: Invalid value: File does not exist: visualsstreamlittime_plot.py
In short, the backslashes are ignored and the path becomes a single file name instead. I'd like some way to be able to launch Streamlit apps using a multi-command via a keyboard shortcut, and I'm open to either of these solutions, or something else I haven't considered:
Send a relative file path that can be parsed correctly regardless of which terminal is the default terminal.
Launch a Windows command prompt even when Git Bash is the default terminal, and activate the Streamlit app there.
Change the working directory to the directory containing the streamlit file (again regardless of which terminal is the default terminal) and launch the file there without having to give a path.

How to pass arguments to existing vscode commands

I would like to be able to run an existing vscode command or extension and pass arguments to it. From my research so far this is what I would expect the vscode task.json to look like, but it does not work. What am I doing wrong?
{
"label": "open index html in editor",
"command": "${command:workbench.action.files.openFile}",
"args": ["/home/host_user/src/index.html"]
},
{
"label": "liveView index html",
"command": "${command:extension.liveServer.goOnline}",
"args": ["/home/host_user/src/index.html"]
},
If I run the file command it opens a vscode prompt to select a file. If I try to liveView the file, it runs live view on my root workspace (as no path is getting passed to it).
This is the extension I'm trying to open with file with:
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
Thanks

VSCode is suddenly defaulting to powershell for integrated terminal and tasks

When I woke up this morning and launched VSCode my default terminal on launch, and when running tasks is now powershell, instead of Git Bash. I am on windows. I have tried changing the settings.json to no avail. Is there something I'm missing?
{
"workbench.startupEditor": "newUntitledFile",
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"[javascript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"aws.samcli.location": "C:\\Users\\king\\AppData\\Roaming\\npm\\sam.exe",
"typescript.updateImportsOnFileMove.enabled": "always",
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDragAndDrop": false,
"diffEditor.maxComputationTime": 0,
"extensions.ignoreRecommendations": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.renderControlCharacters": true,
"[jsonc]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"window.zoomLevel": 0,
"editor.accessibilitySupport": "off",
"workbench.editor.untitled.hint": "hidden",
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
"terminal.explorerKind": "external",
"terminal.integrated.automationShell.linux": ""
}
I found this related SO post making the default powershell, but I didn't see anything that was incorrect about my setting...especially because my goal is the opposite- to stop Powershell!
Update: Version v1.60.0 had a bug. Upgrade to v1.60.1 or higher for a fix.
The bug manifested in the following symptoms:
The Open in Integrated Terminal shortcut-menu command in the Explorer pane's shortcut always uses the built-in default shell (PowerShell on Windows), ignoring the configured one.
The same goes for running tasks (with or without a separate terminal.integrated.automationShell.* setting).
Also, if a given folder or workspace happened to have an integrated terminal open when quitting Visual Studio Code, the shell that is launched when the integrated terminal automatically reopens the next time is again the built-in default shell, not the configured one. By contrast, if reopening doesn't auto-open the integrated terminal, opening it manually does respect the configured default shell, and so does manually creating another shell instance later.
See GitHub issue #132150
The following information turned out to be unrelated to the bug, but is hopefully still useful general information about Visual Studio Code's recent change in how shells for the integrated terminal are configured:
Migrating from the legacy default shell settings to shell profiles:
Recently, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings were deprecated and replaced with a more flexible model that allows defining multiple shells to select from, via so-called shell profiles, optionally defined in setting "terminal.integrated.profiles.*", with an associated mandatory "terminal.integrated.defaultProfile.*" setting referencing the name of the profile to use by default - which may be an explicitly defined custom profile or one of the built-in, platform-appropriate default profiles.
Note: * in the setting names above represents the appropriate platform identifier, namely windows, linux, or osx (macOS).
As of v1.60.1, if legacy "terminal.integrated.shell.*" settings are also present, the new settings take precedence (even though the tooltip when editing "terminal.integrated.shell.*" in settings.json suggests that this change is yet to come).
In the absence of both settings, Visual Studio Code's built-in default shell is used, which on Windows is PowerShell,[1] and on Unix-like platforms the user's default shell, as specified in the SHELL environment variable.
Recent Visual Studio Code versions, starting before v1.60 - seemingly as one-time opportunity - displayed a prompt offering to migrate the deprecated settings to the new ones.
Accepting the migration results in the following:
Creation of setting "terminal.integrated.shell.*" containing a custom shell profile derived from the values of legacy settings "terminal.integrated.shell.*" and, if present, "terminal.integrated.shellArgs.*"; that custom profile's name has the suffix (migrated)
Creation of setting terminal.integrated.defaultProfile.* whose value is the migrated profile's name, making it the default shell.
Removal of legacy settings "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*"
If you decline the migration, you can later effectively perform it by re-choosing the default shell, as described below.
Note: The new "terminal.integrated.defaultProfile.*" setting that is created in the process then effectively overrides the legacy "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings, but the latter won't be removed automatically. To avoid confusion, it's best to remove them from settings.json manually.
Choose the default shell profile to use in order to (re)specify the default shell:
Click on the down-arrow part of the shell-selector icon () on the right side of the integrated terminal, select Select Default Profile, which presents a list of the defined profiles to select the default from - in the absence of explicitly defined profiles, standard profiles are offered (see below).
This translates into a terminal.integrated.defaultProfile.* setting in settings.json, whose value is the name of the chosen shell profile - which may be the name of a built-in profile or one of the ones explicitly defined in "terminal.integrated.profiles.*"
Note: This shell is by default also used for tasks (defined in tasks.json), but that can be overridden with a "terminal.integrated.automationShell.*" setting pointing to the executable of an alternative shell.
Optionally, in your settings.json file, you may create a platform-appropriate terminal.integrated.profiles.* setting with shell profiles of interest:
Note: Even if your settings.json contains no (platform-appropriate) "terminal.integrated.profiles.*" setting, Visual Studio code has built-in standard profiles it knows of and offers them for selection when choosing the default shell.
These standard profiles are a mix of shells that come with the host platform as well as some that Visual Studio detects dynamically on a given system, such as Git Bash on Windows.
To create the standard profiles explicitly, do the following:
Note: You may choose to do this in order to customize the standard profiles. However, if your intent is merely to add custom profiles - see this answer for an example - it isn't necessary to create the standard profiles inside the "terminal.integrated.profiles.*" setting, because Visual Studio Code knows about them even if not explicitly defined.
Via File > Preferences > Settings (Ctrl-,), search for profiles and click on Edit in settings.json below the platform-appropriate Terminal > Integrated > Profiles > * setting; this will open settings.json for editing, with the standard profiles added; simply saving the file is sufficient.
Note: If the "terminal.integrated.profiles.*" setting shown doesn't contain the expected, platform-appropriate standard profiles, a setting by that name may already be present; to force creation of the standard profiles, remove or comment out the existing setting and save the file, then try again.
On Windows, you'll end up with something like the following:
"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"
}
}
The answer you link to in your question, which provides an overview of the various types of shells used in Visual Studio Code, has been updated to reflect the information about the new shell profiles.
[1] Note: If a PowerShell (Core) v6+ installation is found, it takes precedence over the built-in Windows PowerShell version.
Edit:1
Note: Now this bug has been fixed by VSCode. Just update your VSCode to the latest version. (17-Sep-2021)
I have a temporary solution.
First paste this code in settings.json and save
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"C:\\Program Files\\Git\\bin\\bash.exe": {
"path": "",
"args": []
}
},
Before closing VSCode select Output instead of Terminal
Now you can open VSCode
After VSCode is loaded, you need to click on Terminal. After this you will now see bash.
Select output before whenever you close VSCode.
Reference: VSCode is suddenly defaulting to PowerShell for integrated terminal instead of $Bash in Windows
Note: This is not an solution. I shared this because maybe it can save you from getting disappointed.
This is my first post, if there is any mistake please let me know so that I can correct it.
You can always download and install previous releases from the official website https://code.visualstudio.com/updates/v1_59 (currently at the top).
As version 1.60 was bugged, v1.59 is a good candidate.
Disable automatic updates
Explained here.
Open User Settings File > Preferences > Settings.
Add "update.mode": "none" to your settings.
Install older version
Afterwards you can just overwrite current version with the installation of downloaded version.
Note: Wait for next version to fix it, so remember you had automatic update disabled!
I have same problem but I try run command prompt. I fix it by adding to ...\Code\User\settings.json
"terminal.integrated.automationShell.windows": "cmd.exe",
This could be related to issue 138999 which will add a mitigation/enhancement to VSCode 1.70 (July 2022) with PR 154290 and commit 91b82c0
increase barrier for available profiles to be ready
Wait up to 20 seconds for profiles to be ready so it's assured that we know the actual default terminal before launching the first terminal.
This isn't expected to ever take this long.
For VSCode with synchronized user settings, the profile might take more time than expected to fully load, hence the advantage of that workaround.
Simply replaced the CMD by Git Bash :-) in the settings.json
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
//"${env:windir}\\Sysnative\\cmd.exe",
//"${env:windir}\\System32\\cmd.exe"
"C:\\PrivateProgramms\\Git\\bin\\bash.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
//"path": [ "C:\\PrivateProgramms\\Git\\bin\\bash.exe" ],
//"args": [],
//"icon": "terminal-cmd"
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt"

Integrated terminal setup for msys mingw not working for build task

I have managed to get the integrated terminal working with msys (bash) terminal using the following settings:
"terminal.integrated.shell.windows": "C:\\msys64\\bin\\msys_shell.cmd",
"terminal.integrated.shellargs.windows": "-mingw64 -defterm -nostart",
"terminal.integrated.env.windows": "HOME": "${workspace Folder}"
And this works well. I had to add the env "HOME" entry to get the sh to start in the correct home directory as it wouldn't work with (or with nothing at all):
"terminal.integrated.cwd": "${workspaceFolder}"
Now I have run into another problem. While the above settings work perfectly for a terminal window they fail for the build task. So I am forced to manually "make" from the integrated terminal window.
It fails with with error:
/d: /d: is a directory
My environment is Windows 10 msys64 mingw64.
Any ideas appreciated!
I ran into the same issue today. On their help page for tasks.json they talk about the options fields in the settings.
VSCode uses the default shell for tasks unless you tell it not to. Additionally you'll have to pass your command to the resulting shell. I solved that using -shell bash -c so bash runs the command immediately.
The syntax is something like this:
"command": "make -j8",
"options": {
"shell": {
"executable": "C:\\msys2\\msys2_shell.cmd",
"args": ["-defterm", "-mingw64", "-no-start", "-here", "-shell bash -c"]
}
}