Default directory for zsh (cygwin) terminal is home not working directory VSCode on Windows - visual-studio-code

I have setup custom profile for zsh via Cygwin in VSCode as below:
"terminal.integrated.profiles.windows": {
"zsh": {
"path": "C:\\cygwin64\\bin\\bash.exe",
"args": ["--login", "-c", "zsh"],
"overrideName": true,
"color": "terminal.ansiRed"
}
},
"terminal.integrated.defaultProfile.windows": "zsh",
But the default directory is /home/ADMIN, not my working directory (repo directory of source code I'm working). Does anyone know how to solve this problem? Thank you in advance.

Try
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1"
},

Related

home directory is unpreferable location in msys2 shell in integrated teriminal of vscode

I want to use msys2 as a integrated terminal in vscode, so I added this configulation to my user setting.json in vscode.
"terminal.integrated.profiles.windows": {
"MSYS2 UCRT64": {
"path": [
"C:\\msys64\\usr\\bin\\bash.exe",
],
"args": [
"--login",
"-i"
],
"env": {
"MSYSTEM": "UCRT64",
"CHERE_INVOKING": "1",
"MSYS2_PATH_TYPE": "inherit"
}
},
},
"terminal.integrated.defaultProfile.windows": "MSYS2 UCRT64",
And when I open the vscode and toggle terminal window, the msys2 launch, but its start folder is not the same with the one when I launch it from installed location(c/msys64/ucrt64.exe).
shumbow#DESKTOP-STEUAV4 UCRT64 /c/Users/shumbow
$ pwd
/c/Users/shumbow
This is when I launch it from install location.
shumbow#DESKTOP-STEUAV4 UCRT64 ~
$ pwd
/home/shumbow
Could anyone teach me the way I can make these two same?
#HolyBlackCat Removing the CHERE_INVOKING env variable did the trick!(answer by HolyBlackCat). Thanks.

Is there a way to open non-default terminals in VSCode with a keybinding?

I looked at VScode's main site and this site: https://vspacecode.github.io/docs/default-keybindings/
And both only have an option to open the native console with vscode as workbench.action.terminal.openNativeConsole
In my settings.json, I have the following:
"terminal.integrated.profiles.linux": { "bash": { "path": "bash", "icon": "terminal-bash" }, "zsh": { "path": "zsh" }, }
I'd like to be able to open a non-default shell with a keybinding. There does not appear to be a command for this. Is there a way to do this?

integrated (gnome-terminal) zsh vscode \ IDE webstorm

Hi all.
I'm having a problem in integrating a customized zsh shell into vscode and webstorm IDE.
By default, both code editors see the path to zsh at zsh, however, vscode writes
'The terminal process "/home/cstrp/zsh" failed to launch (exit code: 1).' and added path to /usr/bin/zsh vscode writes: 'Value is not accepted. Valid values: null, "sh", "bash", "sh (2)", "bash (2)", "JavaScript Debug Terminal".(1)'
config vsCode
"terminal.integrated.profiles.linux": {
"bash": null,
"zsh": {
"path": "zsh",
"args": [
"-l"
]
},
},
// "terminal.integrated.linux": "zsh",
"terminal.integrated.automationProfile.linux": {
"path": "zsh",
},
default shell
my pc
It was only necessary on behalf of the super user to install all the code editors in the right place

vscode allow only wsl terminal in a workspace

I have these settings in my workspace:
"terminal.integrated.defaultProfile.windows": "Ubuntu-20.04 (WSL)",
"terminal.integrated.profiles.windows": {
"Ubuntu-20.04 (WSL)": {
"path": [
"C:\\WINDOWS\\System32\\wsl.exe"
],
"args": [],
}
},
I want to either disable all others or set it wsl as default.
I still have all the rest in my list:
When I set wsl as default, its working only when I create a new terminal...
How can I remove all the others and stay only with wsl?
Thanks

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