vscode 集成 cygwin 的注意事项

vscode 集成 cygwin

vscode 现在是我的主力开发编辑器,它自带 terminal 不需要我各种切换,我还想要在 windows 下执行一些简单的 .sh 文件。所以,我希望有一款工具能够在 windows 下使用 linux shell 的命令,并且能和 vscode 集成。Cygwin 刚好能够满足我的小小需求。

Cygwin 的下载和安装自不必说,网上有很多教程,要是想偷懒,根据提示一直点击“下一步”就成。

更换 vscode terminal 为 Cygwin

vscode 官方文档说明了如何集成 Cygwin 的 Shell:

https://code.visualstudio.com/docs/editor/integrated-terminal

Can I use Cygwin's shell with the terminal on Windows?
Yes, to use the Cygwin shell, you will first need to install the chere package and then add the following settings to your settings.json file:

"terminal.integrated.shell.windows": "C:\Cygwin\bin\bash.exe",
"terminal.integrated.shellArgs.windows": ["/bin/xhere", "/bin/bash"]

然而直接 copy 配置,是不会成功。需要更改安装目录,如下:

// cygwin 的安装目录
"terminal.integrated.shell.windows": "E:\cygwin64\bin\bash.exe",
// 使得 cygwin 切换到当前工作目录
"terminal.integrated.env.windows": {
    "CHERE_INVOKING": "1"
},
// 使 cygwin 能够在 vscode 中正常使用 Shell 命令
"terminal.integrated.shellArgs.windows": [
    "-l"
],

使用 git

如果你没有使用过 git 登录过远程仓库,那么你只需要点击这里

如果你已经使用过,那么通过 cygwin shell 执行 git 登录,需要将原来的 .ssh/ 文件夹拷贝到 cygwin shell 用户目录的文件夹下。

用我的机器举个栗子:

我的电脑名是 廖大爷,我的 cygwin 安装在 E:cygwin64

打开 cygwin shell 命令行窗口,显示默认的用户目录是 廖大爷@DESKTOP-U6MI28E,实际位置在E:cygwin64home廖大爷,执行 ls -a:

.   .bash_history  .bashrc     .inputrc  .ssh
..  .bash_profile  .gitconfig  .profile

而在我的 C:User廖大爷 文件夹里已经存在了 .ssh/,并且是我正在使用的,所以我并不想生成新的 SSH 公钥,需将原来的内容拷贝到 cygwin shell 的用户目录中,现在我们有了 cygwin shell,不用再操作鼠标:

cp -r C:User廖大爷.ssh ~

可以进入愉快的编码时间啦

其他

Windows下安装和使用Git(Cygwin篇)
Integrated Terminal

原文地址:https://www.cnblogs.com/fayin/p/10185447.html