How do I remove a custom terminal profile from Visual Studio Code? - visual-studio-code

How do I delete the custom profile "New 1" as shown in the picture?

I'm using Zsh, so I suggest configuration
"terminal.integrated.profiles.osx": {
"zsh": {
"path": "/bin/zsh",
"icon": "star",
"env": {
"TESTING_VAR": "abc"
}
}
},
"terminal.integrated.defaultProfile.osx": "zsh",

As described in the Configuring profiles section of the VS Code docs), when you create a custom terminal profile, it adds an entry to your settings.json file:
The recommended way to create a new profile is to run the Terminal: Select Default Profile command and activate the configure button on the right side of the shell to base it on. This will add a new entry to your settings that can be tweaked manually in your settings.json file.
...
"terminal.integrated.profiles.windows": {
"PowerShell -NoProfile": {
"source": "PowerShell",
"args": ["-NoProfile"]
}
},
"terminal.integrated.profiles.linux": {
"zsh (login)": {
"path": "zsh",
"args": ["-l"]
}
}
So open your User settings and you'll find the terminal.integrated.profiles.<OS> setting with an added entry for your custom profile under your corresponding OS. It is better to open the settings.json file directly, or open it from the UI "Edit settings.json":
settings UI
settings.json
"terminal.integrated.profiles.osx": {
"1": {
"path": "bash"
}
}
(I'm using a Mac OS so I have it in .osx. It gets added correspondingly to .linux or .windows)
To remove your custom profile:
Simply delete your custom profile ("1": {...}) from terminal.integrated.profiles
Reload/Restart VS Code
When VS Code reloads/restarts, the removed custom profiles should be gone. (It seems these custom profiles are read and loaded one-time during VS Code startup).
Note though that this only works for custom profiles. For built-in profiles, you'll have to set the profile to null instead:
To remove profile entries from the dropdown, set the name of the profile to null. For example, to remove the Git Bash profile on Windows, use this setting:
"terminal.integrated.profiles.windows": {
"Git Bash": null
}

Related

Customising the application name in a vscode workspace

As directed by the VSCode github repo - I have an simple ask. Is it possible to set a human readable application name for a VSCode Workspace?
At the moment, my .code-workspace file looks like.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
}
Having a look through the Settings (File->Preferences->Settings) for the Workspace there is a plethora of settings. Curiously there is an appName environment variable - but surely there should be a way of customising this.
The title bar looks like the following with acme.app (Workspace):
Curiously the workspace filename is called acme.app.code-workspace.
I spotted window.title in settings when having a look earlier. You can customise it in the code-workspace. I am not sure whether this would be the best way. Would be nice if we could set an environment variable workspaceName or something and use that - if we needed to use elsewhere.
If you add the settings section - then add the window.title it will default the value to ${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
"settings": {
"window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}"
}
}
Here you can see the following:
dirty - displays an indicator of whether the current file has changed
activeEditorShort - the current file
separator - configured separator i.e. '-'
rootName - defaults to acme.app (Workspace)
appName - defaults to Visual Studio Code
So you could change the rootName to be the human-readable text:
"window.title": "${dirty}${activeEditorShort}${separator}MY SUPER PROJECT${separator}${appName}"
Which gives us:

GitBash not showing up as a terminal option in Visual Studio Code

I am trying to insert GitBash as an option in Visual Studio Code. My settings look like so:
"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"
},
"GitBash": {
"source": "GitBash",
"path": ["F:\\Code\\Git\\bin\\bash.exe"],
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
However, at the last line, the error that Visual Studio Code gave is:
Value is not accepted. Valid values: "PowerShell", "Command Prompt".(1)
The default profile used on Windows. This setting will currently be ignored if either #terminal.integrated.shell.windows# or #terminal.integrated.shellArgs.windows# are set.
I do not understand where I went wrong.
Note: "terminal.integrated.shell.windows" is deprecated as of April 2021.
VS Code version 1.57.1.
Added path of Git, Git\bin, Git\cmd in env. Had "Git Bash" profile with source and path elements. Removed source and kept only the path. When adding defaultProfile as "Git Bash" got "Value is not accepted" error. Restarting VS Code did not help.
Changing "Git Bash" to "GitBash" (space removed) finally worked for me:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": ["D:\\ProgramFiles\\Git\\bin\\bash.exe"],
"args": []
},
...
}
"terminal.integrated.defaultProfile.windows": "GitBash"
I am not sure if space is actually the problem. Because there is a profile "Command Prompt" with space in its name and recognized!!! To confirm this further, changed "PowerShell" to "Power Shell", and it worked too.
I am not clear how space matters only in the "GitBash" profile.
I believe Visual Studio Code uses your PATH variables to find which profiles are available on your machine. I am guessing you do not have the location of Git Bash set in your PATH. But, that should be fine since you specify the path property in the setting. The issue is you are also setting the source property. According to the description for the terminal.integrated.profiles.windows setting, you can either set the source or the path, not both:
The Windows profiles to present when creating a new terminal via the terminal dropdown. Set to null to exclude them, use the source property to use the default detected configuration. Or, set the path and optional args
Delete the source property, and see if the issue resolves and you can open a git bash terminal in Visual Studio Code.
Also, you may need to restart Visual Studio Code after making these changes. It might be a separate bug, but the terminal.integrated.profiles.windows setting won't detect any new profiles added until you restart.
For anybody using a custom dir for git installation: It does not work with Version: 1.60.2 (user setup)
Win10 User:
Install or just copy git in C:\Program Files
Add Path Variables name: GIT_HOME_2 variable: C:\Program Files\Git
In double click on Path and add "%GIT_HOME_2%\bin"
Open VS Code, you should now see the bash terminal
{
"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"
},
},
"terminal.integrated.env.windows": {
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
}
I have VS Code 1.63.2
Removing the source property or the space in "Git Bash" didn't help. But I found this on their official site and I noticed that the .exe file itself is specified in path:
{
"terminal.integrated.profiles.windows": {
"My PowerShell": {
"path": "pwsh.exe",
"args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "My PowerShell"
}
So I tried adding \\bash.exe to the path in the settings and it worked:
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
This works for me when pasted in the settings.json:
{
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": [
"C:\\Program Files (x86)\\Git\\bin\\bash.exe"
]
}
}
}
But only if "GitBash" has no spaces. "Git_Bash" is also fine but not "Git Bash".
Use the syntax below if you want "GitBash" to become the default:
{
"terminal.integrated.profiles.windows": {
"GitBash": {
"path": [
"C:\\Program Files (x86)\\Git\\bin\\bash.exe"
]
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
}
In VS code go to File -> Preferences -> Settings
Select edit mode in JSON format and set below property value
"terminal.integrated.profiles.windows": {
"Bash": {
"path": "C:\\Git\\bin\\bash.exe"
},
}
Reopen the VS code and check the terminal list and select bash
By configuring profile as bash in the above format it worked finally!!!
{
"terminal.integrated.profiles.windows":{
"GitBash":{
"path":"D:\\projects\\tools\\Git\\bin\\bash.exe"
},
},
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.linux": {
Changing "Git Bash" to "GitBash" (space removed) worked for me:
I had a similar issue. As Timothy. G pointed out, you can only have "source" or "path", not both. But also, simply restarting VS Code enables the newly created profile.
Here's the one I created to have a conda terminal by default (on windows)
"terminal.integrated.profiles.windows": {
"Conda": {
"path": "C:\\windows\\System32\\cmd.exe",
"args": [
"/K", "C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat C:\\ProgramData\\Anaconda3"
],
"icon": "squirrel"
}
},
"terminal.integrated.defaultProfile.windows": "Conda",
This worked for me:
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\\ProgramFiles\\Git\\bin\\bash.exe"
},
"PowerShell": {
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
}
}
Remove the brackets in the path worked for me
Open a new terminal by going to Terminal -New Terminal
In the right drop downlink -Select Default Profile
Then select configure Terminal Profile gear icon
Type the name of the profile that need to be created and press Enter
Then it will open the setting page and change the path to your
terminal path
After struggling with this, a simple solution i found, at least in my case where git is not installed in default path, is to make a symbolic link with this command:
mklink /d "C:\Program Files\Git" "D:\Archivos de Programa\Git"
/d stands for symbolic link.
First path is where the link be located.
Second path is where your Git is actually installed.
After restarting VSCode, i was allowed to see Git Bash on terminal list and set it as default.
The solution is to uninstall git and reinstall it in the default location which is (C:\Program Files\Git). All the other hacks failed.
On Windows - Sept 2022
Open VS Code JSON Settings
Open VS Code
'Ctrl + ,' Control key combined with comma at the same time
At the top right corner of VS Code, click on the File icon - with a tooltip of Open Settings (JSON)
Now add this code to your JSON file
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.external.windowsExec": "C:\\Program Files\\Git\\git-bash.exe",
Note: If you installed Git in a different partition on windows, kindly change the drive to its correct letter and not 'C://'
Win11, VS Code 1.71.2
maybe you should try this
failed (Value is not accepted...)
"terminal.integrated.profiles.windows":{
"GitBash": {
"path": "D:\\dev\\Git\\bin\\bash.exe"
},
...
},
"terminal.integrated.defaultProfile.windows": "GitBash",
work
"terminal.integrated.profiles.windows":{
"GitBash": {
"path": "D:/dev/Git/bin/bash.exe"
},
...
},
"terminal.integrated.defaultProfile.windows": "GitBash",
As of February 2023 (version 1.75.0), the following settings 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": [],
"icon": "terminal-cmd"
},
"GitBash": {
"path": "${env:homepath}/Software/git/current/bin/bash.exe",
"icon": "terminal-bash"
},
},
"terminal.integrated.defaultProfile.windows": "GitBash",
}
I downloaded/installed the 64-bit Git binaries to a user directory.
Visit Git - Download for Windows
Locate the Portable ("thumbdrive edition") section
Choose architecture e.g. 64-bit ~ https://github.com/git-for-windows/git/releases/download/v2.39.1.windows.1/PortableGit-2.39.1-64-bit.7z.exe
Install Git to your user directory e.g. "Software/Git"
Notes
You do not need to install Git to C:\Program Files\Git
You can use forward-slash / instead of an escaped back-slash \\ in paths
Spaces are not allowed in the profile name/key. Use either "GitBash" or simply "Bash"
If you want to change the "icon" value for your GitBash profile to e.g. Git/GitHub-related icons, you can just use the value "github" or "git-merge". You can use any of VS Code's codicon values as a terminal icon.
See also
DEV - How to set Git Bash as integrated terminal in VSCode in 2021

problem loading in ${localEnv:TOKEN} into devcontainer.json

In my devcontainer.json for vscode, I am trying to load in a build variable. This variable is on my local machine's environment, my code looks like the following:
//build arguments
"build": {
"args": {
"TOKEN": "${localEnv:TOKEN}"
}
}
It seems like it works when I put in a direct string, or something like "${localEnv:HOME}", but it is not picking up this custom one. which is strange because I can do 'printenv TOKEN' and it prints out correctly.
any ideas on what I may be doing wrong?
Add your export BLA=1 to .profile, this was the only way VScode was able to pass through env variables to the devcontainer.
.devcontainer:
{
"name": "devcontainer",
"build": {
"dockerfile": "${localWorkspaceFolder}/Dockerfile",
"context": "${localWorkspaceFolder}",
},
"remoteEnv": {
"FOO": "${localEnv:FOO}",
"BAR": "${localEnv:BAR}",
}
}
First, ensure that you have the VS Code Terminal -> Integrated: Inherit Env setting set to true. This is described on the Advanced Container Configuration page:
Workarounds
If that doesn't fix your problem (it didn't for me), here are some of the workarounds that I have found:
Set the variables in your ~/.bashrc file (or export them temporarily in the terminal) and start VS Code from a bash prompt (the executable is code).
$ export TOKEN=tokenvalue
$ code
Set the variables in your ~/.pam_environment file (these are available session wide and are inherited by applications started with the launcher). You will need to logout and login or reboot for these to apply.
TOKEN=tokenvalue
Set the environment variables in one of your VS Code settings files (user or workspace) using the Terminal -> Integrated Env: Linux setting:
// Object with environment variables that will be added to the VS Code process to be used by the terminal on Linux. Set to `null` to delete the environment variable.
"terminal.integrated.env.linux": {
"TOKEN": "tokenvalue"
},

Visual Studio Code Run On Save Extension not running

I installed the Run On Save extension for VS Code. I made a Workspace setting for it, and if I change a file then resave, it does not seem to run. "I run for all files" does not show up in the console or terminal.
When I chose to edit the command configuration in my Workspace settings, it automatically edited the file with the comment "Place your settings in this file to overwrite default and user settings." so it looks like this:
// Place your settings in this file to overwrite default and user settings.
{
"editor.mouseWheelZoom": false,
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
I'm new to configuring Workspace settings, so I'm not sure if this is okay or not. I ensured that Run On Save is enabled by selecting it on the command palette.
Here is the site for the extension: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
In order to see the console output, you have to be in the Output tab and select the Run On Save option in the dropdown. The extension was created before the integrated terminal existed and hasn't seen a major update in a while.
Regarding the comment that was added to your config:
// Place your settings in this file to overwrite default and user
settings.
is unrelated to this particular extension. It is just vscode letting you know the purpose of the workspace level configuration. It allows you to override a subset of your more global user / default settings. This allows you to keep reasonable default preferences but to customize certain specific things in any given workspace.
Regarding the original RunOnSave extension, feel free to file an issue here https://github.com/emeraldwalk/vscode-runonsave/issues if you have any questions or problems. I would also welcome pull requests if anyone is interested.
I had the exact same issue. I removed that extension and am using this one instead:
https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
It is a fork based on RunOnSave. This one works for me when I set its configuration in my user settings and then run the command "Save and Run: Enable".
This one uses the bulit-in powershell terminal.
HTH
In addition to our dear #bingles, I have accidentally discovered that the commands should be added to .vscode/settings.json file instead of .vscode/emeraldwalk.runonsave as said in the plugin documentation
Add it to settings.json and everything should work as expected.
For the extension to work on Workspace you must put the emeraldwalk.runonsave inside settings:
{
"settings": {
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
}
A related one:
Previously I used RunOnSave, this time around I used Code Runner.
Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Below are it's settings I used:
File: %AppData%\Code\User\keybindings.json
{
{
"key": "ctrl+s",
"command": "code-runner.run"
}
}
File: .vscode\settings.json
{
"code-runner.saveFileBeforeRun": true,
"editor.codeActionsOnSave": [
"code-runner.executorMap"
]
"code-runner.executorMap": {
"javascript": "node a.js"
},
}
If possible, you could use Code Runner with the above settings, or use a similar to the above settings for the RunOnSave.
Note that RunOnSave has its own tab which is time-consuming to switch to another tab.
With Code Runner I can see the output in the Output tab itself which is a very nice thing, saves time.

missing items from Command palette in ST2

I'm trying to create a custom package and one thing I would like to do is bring up the Build Systems(located in the Tools menu item) in the command palette(show_overlay). So I have tried to create a Default.sublime-commands file in my package and type in...
[
{ "caption": "Build System", "command": "build_system" }
]
...to enable that menu item for the command palette(I also tried set_build_system) and then I created a Default.sublime-keymap file in my package so that I can access the Build System list from via shortcut...
[
{
"keys": ["f9"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Build System"}
}
]
I am not having any luck exposing the Build System menu item to the command palette. Can I get some help on this? I also noticed the Tools menu item is not available in the command palette as well. What am I missing?
Ok I figured it out. The command palette can only be populated by existing commands that run in sublime. The way you can view which commands that are being run in sublime is to open up the console(CTR + ~) and type in sublime.log_command(True)
Now whenever you do anything that makes sublime trigger a command, it will log that action in the console. Armed with this knowledge, we we go to Tools > Build System and click on the build system type we want, say, C++, we get:
command: set_build_system {"file": "Packages/C++/C++.sublime-build"}
Sweet! Knowing this we can go to our .sublime-commands file(you can call it Default.sublime-commands) and type in the below code:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
}
]
Tip: pay close attention to the "caption" it's what we will use to tie our .sublime-command file with our .sublime-keymap file. Let's add another one build system:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
},
{
"caption": "Set Build System: Python", "command": "set_build_system",
"args": { "file":"Packages/Python/Python.sublime-build" }
}
]
Now that we have exposed these two commands in our .sublime-commands file. We can create a shortcut for it in our .sublime-keymap file. I called mine Default.sublime-keymap:
[
{
"keys": ["f8"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Set Build System:"}
}
]
Notice the "text" key. Look familiar? This is how you connect your key binding to your command. Save press F8 and boom! You have our own custom command palette menu. Enjoy!
PS: you can put your .sublime-commands/.sublime-keymap files in your User package or add to any existing ones if you have them there if you just want to customize your sublime text 2 without making a custom package.