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:\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\ ~
可以進入愉快的編碼時間啦