首页 > Windows开发 > 详细

vscode 集成 cygwin 的注意事项

时间:2018-12-27 17:13:09      阅读:508      评论:0      收藏:0      [点我收藏+]

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"]

不幸的是,这样配置不会成功。为此我特地更新 vscode 到最新版:2018-12-18 v1.30.1,依然失败。

经过不断的调试,以下配置是可行的:

// 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:\cygwin64\home\廖大爷\,执行 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

vscode 集成 cygwin 的注意事项

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!