'VS Code - Cygwin as Integrated Terminal
I would like to use Cygwin as the integrated terminal on Visual Studio Code on my Windows laptop (as this would give me use of the Linux terminal commands git and G++, etc.) but when I set the value for "terminal.integrated.shell.windows": to the address of the Cygwin application (.exe) then it opens a new Cygwin terminal rather than remaining in VS Code.
So my question is: can I use Cygwin integrated into the VS Code terminal and use that to use commands on it (mkdir, rm, etc.) but also use git commands and use it as an integrated compiler and debugger (for generically but for C++ at least)? And how would I go about this?
Solution 1:[1]
These config settings work for me:
{
// start bash, not the mintty, or you'll get a new window
"terminal.integrated.shell.windows": "C:\\cygwin\\bin\\bash.exe",
// Use this to keep bash from doing a 'cd ${HOME}'
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1"
},
// Make it a login shell
"terminal.integrated.shellArgs.windows": [
"-l"
],
}
Solution 2:[2]
You could just call the Cygwin.bat without ENV issue:
{
// Replace with your Cygwin.bat file path
"terminal.integrated.shell.windows": "C:\\cygwin64\\Cygwin.bat",
}
Make sure the BAT scripts fit to your Cygwin.
Solution 3:[3]
Combining above answers, this is my working configuration.
{
"terminal.integrated.shell.windows": "C:\\cygwin\\bin\\bash.exe",
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1"
},
"terminal.integrated.shellArgs.windows": [
"--login",
"-i"
],
}
{tested at ubuntu 18.04lts, running Windows 7 ultimate 32bt in Virtualbox 5.2.12}
Solution 4:[4]
VS Code only allows you to set one default terminal configuration at a time and as its likely that users would want multiple shells to be available at any time like CMD, Powershell and Cygwin Bash, it would be best to use an Visual Studio Code Extension called Shell Launcher.
This tool will allow you to launch any number of shells at any time. First you need to reassign the CTRL-SHIFT-T hotkey to shellLauncher or use a different unused hotkey.
Then, go into your settings.json for VS Code and add the following block:
"shellLauncher.shells.windows": [
{
"shell": "C:\\Windows\\System32\\cmd.exe",
"label": "cmd"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"label": "PowerShell"
},
{
"shell": "C:\\cygwin\\bin\\bash.exe",
"args": ["-l"],
"env": {"CHERE_INVOKING": "1"},
"label": "Cygwin Bash"
}
],
Note: alter paths above as required
Now when you hit the hotkey you assigned, you will get a dropdown of the available terminals configured.
Solution 5:[5]
Since VS Code 1.55 (March 2021), you can use terminal profiles.
- Select File > Preferences > Settings
- Select the Open Settings (JSON) icon (top right, same level as tabs)
- Copy and paste the code below inside the top-level curly braces {}
"terminal.integrated.profiles.windows": {
"Cygwin": {
"path": "C:\\cygwin\\bin\\bash.exe",
"args": ["--login"],
"env": {"CHERE_INVOKING": "1"}
}
}
If you have 64-bit, your Cygwin path may need to be:
"path": "C:\\cygwin64\\bin\\bash.exe",
To open the Cygwin terminal
- Press F1
- Type: Terminal: Create New Terminal (with Profile)
- Select Cygwin
Solution 6:[6]
For VS Code v1.60 works the following approach:"
"terminal.integrated.profiles.windows": {
"Cygwin": {
"source": "PowerShell",
"args": ["C:\\cygwin\\cygwin.bat -i /Cygwin-Terminal.ico -"]
}
}
As disadvantage: opened directory will be the root folder.
Solution 7:[7]
If you take out the following part the terminal starts in the project you have open.
// Make it a login shell
/*"terminal.integrated.shellArgs.windows": [
"--login"
"-l"
]*/,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Davis Herring |
| Solution 2 | Nick Tsai |
| Solution 3 | Ben Voigt |
| Solution 4 | Timothy C. Quinn |
| Solution 5 | DBolton |
| Solution 6 | AlexK |
| Solution 7 | Juan Andres Stingo |
