Linux終端式bash,win10的終端是powershell或命令提示符,兩種終端的語言相差較大,尤其是一些斜杠/和反斜杠\,單引號'和雙引號"的區別很難記憶。因此,git bash是一款用Linux的bash語言控制windows的解決方案(bash for windows),對於windows的腳本編寫,vscode是一個非常強大的工具,比visual studio,pycharm適用的語言更多,和sublime相比,能夠運行各種腳本。但是缺點是內存和磁盤占用更大。因此,對於沒有win+linux雙系統,windows上沒有Linux子系統的用戶來說,git+vscode是一個非常友好的bash for windows的編程環境組合。
git安裝配置過程
1.下載。下載地址有兩個https://gitforwindows.org/或者https://git-scm.com/download/win都可。
2.安裝路徑選擇,選擇要安裝的位置,默認為/bin/bash,那么每次shell腳本開頭的聲明為#!/bin/bash。如果我的bash安裝在D:\tools\git\Git\bin\bash的話,那么每個shell腳本開頭的聲明需要改寫為#!/d/tools/git/Git/bin/bash
3.安裝選項。勾選Windows Explorer integration, Git LFS, Associate .git* configuration files with the default text editor, Associate .sh files to be run with Bash
4.在開始菜單中創建git,點擊next
5.選擇vim作為git默認的編輯器,點擊next
6.調整環境變量,我選擇的是use Git from Git bash only,使用git自帶的命令行工具。如果選擇git from the command line and also from 3rd-party software則代表選擇windows命令行,點擊next
7.選擇http transport backend,我選擇Use the OpenSSL library,點擊next
8.配置換行符設置,我選擇checkout windows-style, commit Unix-style line endings自動轉換文件中的換行符,點擊next
9.配置終端仿真器,我選擇MinYY默認的MSYS2終端,點擊next
10.選擇默認的git pull行為,我選擇默認,點擊next
11.選擇憑據存儲credential helper,我選擇git credential manager,點擊next
12.配置外部選項,勾選enable file system caching和enable symbolic links和enable experimental support for pseudo consoles,點擊install。
安裝完成,打開如下圖所示,跳轉到releaseNote.html中file:///D:/tools/git/Git/ReleaseNotes.html
git的可用模塊共三個,一種是git GUI如下圖,一種git bash模擬Linux終端,一種git cmd模擬windows終端。
vscode安裝配置過程
腳本式編程我推薦vscode,還可以將各種終端植入vscode中,將代碼在vscode中直接運行。植入方法見攻略。
首先下載地址https://vscode.en.softonic.com/或https://code.visualstudio.com/都可。
雙擊安裝,同意協議,選擇安裝路徑,添加到開始菜單的程序中,勾選添加到PATH,點擊安裝即可。
vscode的配置過程包括安裝拓展extension和植入終端。
我安裝的拓展包括:簡體中文Chinese (Simplified) Language Pack for Visual Studio Code,fortran程序顏色標注
植入的終端是git bash:點擊file-preferences-settings,然后搜索“terminal.intergrated.shell.windows”,點擊下面的edit in setting.json,在其中輸入git的路徑即可
{ "terminal.integrated.shell.windows": "D:\\tools\\git\\Git\\bin\\bash.exe" } #注意:為了避免將\識別為轉義字符,我們將使用雙反斜杠\\來書寫bash.exe的路徑。
然后點擊快捷鍵ctrl+~即可出現已經植入的git bash作為terminal了。在terminal右側的選項中還可以選擇默認的shell(select default shell),其中可以選擇Command Prompt,Windows PowerShell,還可以選擇WSL shell。
配置完成