windows VS Code - Cygwin 作为集成终端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46061894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VS Code - Cygwin as Integrated Terminal
提问by user2766296
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.
我想在我的 Windows 笔记本电脑上使用 Cygwin 作为 Visual Studio Code 上的集成终端(因为这会让我使用 Linux 终端命令 git 和 G++ 等)但是当我将值设置为 "terminal.integrated.shell.windows":
Cygwin 的地址时application ( .exe
) 然后它打开一个新的 Cygwin 终端而不是留在 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?
所以我的问题是:我可以使用Cygwin集成到VS代码终端和使用其在其上使用的命令(mkdir
,rm
等),但也使用git命令并用它作为一个集成的编译和调试(对于一般性但C ++在至少)?我该怎么做呢?
回答by Rick Renshaw
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"
],
}
回答by Nick Tsai
You could just call the Cygwin.bat
without ENV issue:
你可以调用Cygwin.bat
没有 ENV 的问题:
{
// Replace with your Cygwin.bat file path
"terminal.integrated.shell.windows": "C:\cygwin64\Cygwin.bat",
}
Make sure the BAT scripts fit to your Cygwin.
确保 BAT 脚本适合您的 Cygwin。
回答by Στρατ?? Χριστοδο?λου
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}
{在 ubuntu 18.04lts 上测试,在 Virtualbox 5.2.12 中运行 Windows 7 Ultimate 32bt}
回答by Timothy C. Quinn
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.
VS Code 一次只允许您设置一个默认的终端配置,并且由于用户可能希望在任何时候都可以使用多个 shell,例如 CMD、Powershell 和 Cygwin Bash,最好使用名为的 Visual Studio Code 扩展壳牌发射器。
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.
此工具将允许您随时启动任意数量的 shell。首先,您需要将 CTRL-SHIFT-T 热键重新分配给 shellLauncher 或使用其他未使用的热键。
Then, go into your settings.json for VS Code and add the following block:
然后,进入 VS Code 的 settings.json 并添加以下块:
"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.
现在,当您按下您分配的热键时,您将获得已配置的可用终端的下拉列表。