開門見山
git bash
是
Windows
使用者安裝
git
時預設安裝的指令行工具,不僅界面漂亮功能也不錯,大多數情況下可以替代
Windows
原生的
cmd
指令行.
然而,
git bash
指令行不是萬金油,并不能完全替代
cmd
,詳情請參考
mintty
官網的相關說明.
mintty is not a full replacement for the Windows Console window
git bash
指令行預設使用
mintty
作為終端模拟器,而
mintty
官宣表示自己不能完全替代
cmd
,也就是說
git bash
可能不具備某些
cmd
指令.
舉個簡單的例子,如果想要檢視目前目錄的檔案結構,最好是以目錄樹的形式展現,聰明的你擷取已經猜到了
tree
git bash
指令行中輸入
tree
指令發現并無此指令.
snowdreams1006@home MINGW64 /g/sublime/test
$ tree
bash: tree: command not found
為了驗證,确實沒有
tree
指令,我們直接打開
git bash
支援的指令檔案目錄,檢視到底有沒有
tree.exe
檔案.
在桌面快捷方式右鍵,選擇打開檔案位置,目前正處于
git bash
的安裝目錄,進入
git
檔案夾.
.\usr\bin
經過驗證,
git bash
支援的指令檔案确實沒有發現
tree.exe
檔案,是以真的不支援
tree
cmd
自帶的指令行中輸入
tree
中竟然發現能夠輸出目錄樹,原來
cmd
支援
tree
G:\sublime\test>tree
卷 工作 的檔案夾 PATH 清單
卷序列号為 00000081 CC3C:50D0
G:.
├─cmd
└─git
指令其實調用的是
tree
并不是常見的
tree.com
格式.
tree.exe
科普時間
現在我們已經知道
git bash
提供的終端模拟器不支援某些
linux
指令,但是為什麼不支援以及如何才能支援這些指令呢?
這些問題必須等我們弄清楚
mintty
的朋友圈關系才能更好地解決上述問題,接下來簡單科普下
mintty
的朋友圈.
關于科普知識的來源,請參考上一篇文章: <<git bash 背後的朋友圈>>
mintty
是什麼
mintty
Mintty
,
Cygwin
或
MSYS
的終端模拟器,派生項目和
Msys2
.
WSL
mintty
開源終端模拟器,基于
putty
的終端仿真和
Windows
前端頁面.
mintty
作為一款優秀的終端模拟器,不僅是其他系統上預設的終端,也是
git bash
的預設終端.
$ mintty --help
Usage: mintty [OPTION]... [ PROGRAM [ARG]... | - ]
Start a new terminal session running the specified program or the user's shell.
If a dash is given instead of a program, invoke the shell as a login shell.
Options:
-c, --config FILE Load specified config file
-e, --exec Treat remaining arguments as the command to execute
-h, --hold never|start|error|always Keep window open after command finishes
-i, --icon FILE[,IX] Load window icon from file, optionally with index
-l, --log FILE|- Log output to file or stdout
-o, --option OPT=VAL Override config file option with given value
-p, --position X,Y Open window at specified coordinates
-s, --size COLS,ROWS Set screen size in characters
-t, --title TITLE Set window title (default: the invoked command)
-u, --utmp Create a utmp entry
-w, --window normal|min|max|full|hide Set initial window state
--class CLASS Set window class name (default: mintty)
-H, --help Display help and exit
-V, --version Print version information and exit
如果想要自定義
mintty
終端,在
git bash
指令行界面右鍵選擇選項設定即可打開設定頁面.
mingw
mingw
mingw
的縮寫,是
Minimalist GNU for Windows
應用程式的極簡主義開發環境.
Microsoft Windows
msys
msys
MSYS
Minimal SYStem
指令行解釋器系統.作為
Bourne Shell
的
Microsoft
的替代品,它提供了一個通用的指令行環境,特别适合與
cmd.exe
一起使用,用于将許多開源應用程式移植到
MinGW
平台; 它是
MS-Windows
的輕量級分支,它包含一小部分
Cygwin-1.3
工具,可以幫助實作這一目标.
Unix
cygwin
cygwin
大量和開源工具,提供類似于
GNU
上的
Windows
發行版的功能.
Linux
gnu
gnu
GNU
的遞歸縮寫,是自由軟體作業系統.
GNU's Not Unix
朋友圈關系梳理
git bash
采用
mintty
mintty
終端是
mingw
,
msys2
和
cygwin
的預設終端,這些"作業系統"或多或少都是
GNU
的一部分.
GNU
是自由軟體運動的成果,提出自由軟體以及自由軟體作業系統概念,源碼開源釋出.
正因如此,江山代有才人出,前人栽樹後人乘涼,
Cygwin
作為
GNU
一員,提出了要在
Windows
打造出
Linux
的感覺,開發出一套完整的解決方案.
或許由于這套方案太完整,功能齊全因而軟體包體積龐大,是以
MinGW
MSYS
分别在其基于上進行精簡重構,保留最簡功能,發展出"極簡主義的GNU".
開源的力量是可持續的,慢慢的,這些作業系統的内置終端功能也被單獨提取出來,
mintty
作為他們的預設終端也逐漸獨立提供終端模拟器服務,輕松和各個系統進行安裝內建.
說到開源,自然是少不了
git
的身影,分布式版本控制系統這種優秀工具應該造福全人類,然而
git
本身僅支援類
Unix
系統,并不提供
WIndows
系統的支援.
Git For Windows
組織出手增加了
git
對
Windows
系統的支援,背後的技術多半離不開上述介紹的
GNU
作業系統.
Git Bash Here
則是
Git For Windows
的指令行工具,使用的終端模拟器就是明星模拟器
mintty
回到正題
弄清楚事情的來龍去脈後,對我們解決問題有什麼幫助呢?
幫助可大了去了,刨根問題找到了源頭,問題自然迎刃而解!
我勸少年放棄吧
你确定不是在逗我?讓我直接放棄?
親,真的抱歉呢,放棄是解決問題的最快途徑!
...
談一談為什麼要放棄?
git bash
指令行使用的是
mintty
終端,而
mintty
終端并不能完全替代
cmd
,也沒有提供包管理工具供我們擴充第三方指令.
是以預設情況下,如果沒有提供某些指令,那我們隻好放棄在
git bash
指令行中使用這些指令.
此路不通,自然會尋求其他解決途徑,比如可以借助
cmd
指令行或者其他第三方軟體等,沒必要非要堅持使用
git bash
!
既然本文是
tree
指令引發的讨論,那就談點和主題有關的技能點,不然豈不是跑題了?
tree
指令雖然
git bash
不提供,但是
cmd
卻已經内置了.
值得注意的是,
cmd
提供的
tree
指令比較特殊,并不是常見的
.exe
結尾檔案,而是
.com
結尾的檔案.
是以
git bash
中輸入
tree
指令時,自身
/usr/bin
中沒有
tree.exe
檔案,而系統中也沒有
tree.exe
指令,那麼就會提示找不到指令了啊!
手動補全指令
那麼第一種調用方法便是補全字尾名,這樣自然能夠調用
cmd
tree.com
并不識别
git bash
字尾的指令,輸入
.com
指令時以為是
tree
,實際上
tree.exe
指令應該是
tree
的簡寫.
tree.com
我擦,竟然出現亂碼,根據我多年的開發經驗來看,亂碼問題多半是編碼問題導緻的,那麼修改下終端的編碼設定應該就能解決問題.
在指令行視窗内右鍵彈出終端的設定頁面,選擇文本(
mintty
)中本地化(
Text
)配置,選擇中文簡體(
Locale
),字元集(
zh_CN
)設定為
Character set
UTF-8
瞬間被打臉,無論是原來的
git bash
指令行視窗還是新開的指令行視窗,仍然還是亂碼!
然而,我是不會承認被打臉的,世人皆醉我獨醒,肯定是
bug
,哈哈!
其實,中文亂碼真的是,還是官方認可的
bug
喲,我并沒有被打臉呢,後續會介紹.
bug
調用 cmd
程式
cmd
既然
git bash
沒有提供
tree
指令,而恰巧
cmd
提供了
tree
指令,那為何不假借他人之手實作自己的目的呢?
cmd
中使用
tree
指令直接輸入即可得到目錄樹結構,但是現在需要在
git bash
中調用
cmd
中的
tree
# 直接輸入 `tree` 指令,正确響應并且無中文亂碼.
G:\sublime\test>tree
卷 工作 的檔案夾 PATH 清單
卷序列号為 00000093 CC3C:50D0
G:.
├─cmd
└─git
# 輸入 `cmd tree` 指令,雖無報錯,但也沒有正确響應.
G:\sublime\test>cmd tree
Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有權利。
中直接輸入
cmd
指令即可,無需通過
tree
這種方式,還以為你要調用
cmd tree
指令呢!
cmd
是以,我們需要告訴
git bash
要通過
cmd
去調用下
tree
# 注意看字首是 `snowdreams1006@home MINGW64` 表明目前處于 `git bash` 環境
snowdreams1006@home MINGW64 /g/sublime/test
# 輸入 `cmd tree` 指令,雖無報錯,但也沒有正确響應,并且仍然有中文亂碼.
$ cmd tree
Microsoft Windows [▒汾 6.3.9600]
(c) 2013 Microsoft Corporation▒▒▒▒▒▒▒▒▒▒Ȩ▒▒▒▒
# 輸出 `tree` 指令,正确響應但有中文亂碼.此時指令行字首已經更改為 `G:\sublime\test>` 表明目前不再處于`git bash` 環境!
G:\sublime\test>tree
tree
▒▒ ▒▒▒▒ ▒▒▒ļ▒▒▒ PATH ▒б▒
▒▒▒▒▒к▒Ϊ 0000006B CC3C:50D0
G:.
▒▒▒▒cmd
▒▒▒▒git
通過上述操作結果來看,不難發現以下問題.
-
指令切換到cmd tree
環境,并且cmd
tree
指令并沒有執行.
換句話說,
cmd tree
或者cmd dir
的作用相同,都是切換了目前cmd
環境.bash
- 進入
指令行運作cmd
能夠得到正确響應,但存在中文亂碼.tree
- 想要退出
環境,cmd
組合即可重新回到Ctrl + C
git bash
由此可見,不加任何參數冒昧進入到
cmd
環境還是比較麻煩的,是以下面提供帶參數的指令幫助我們閱後即焚.
cmd //c tree
指令,閱後即焚,表示執行完立即退出.
snowdreams1006@home MINGW64 /g/sublime/test
$ cmd //c tree
▒▒ ▒▒▒▒ ▒▒▒ļ▒▒▒ PATH ▒б▒
▒▒▒▒▒к▒Ϊ 00000008 CC3C:50D0
G:.
▒▒▒▒cmd
▒▒▒▒git
snowdreams1006@home MINGW64 /g/sublime/test
$
執行指令前後我們都在環境并且在
git bash
中得到正确響應結果,唯一的差別就是多加了
cmd
參數,表示執行完指令立即退出
//c
cmd
優雅調用 cmd
cmd
簡單總結下,如何在
git bash
中借助
cmd
實作
tree
-
: 補全調用指令字尾名,直接調用系統指令.tree.com
-
: 借助cmd //c tree
運作cmd
指令,進而實作調用tree
的目的.tree
- 這兩種方式都存在中文亂碼問題,即使設定了終端的編碼方式也沒有解決亂碼.
tree
指令的目的已經達到,沒有解決的問題是中文亂碼.
解決問題最快速的方式是百度一下或者從官網尋求幫助,這次我選擇後者,因為百度一下人人都會,不用我再講了吧!
簡單解釋下這段話的意思:
如果在
mintty
終端調用原生
cmd
程式,簡單的輸出指令沒有什麼問題,互動指令可能存在問題.
是以建議使用
winpty
進行包裝再調用原生
cmd
程式.
是一種提供與
winpty
通信的軟體包,詳情請參考https://github.com/rprichard/winpty
cmd
有什麼神奇之處?不妨加上
winpty
試試看!
snowdreams1006@home MINGW64 /g/sublime/test
# `winpty` + `tree.com` : 正常輸出且無中文亂碼
$ winpty tree.com
卷 工作 的檔案夾 PATH 清單
卷序列号為 00000074 CC3C:50D0
G:.
├─cmd
└─git
snowdreams1006@home MINGW64 /g/sublime/test
# `winpty` + `cmd //c tree` : 正常輸出且無中文亂碼
$ winpty cmd //c tree
卷 工作 的檔案夾 PATH 清單
卷序列号為 000000B3 CC3C:50D0
G:.
├─cmd
└─git
snowdreams1006@home MINGW64 /g/sublime/test
$
果然是神藥,一下子就治好了我多年的老寒腿啊!
-
: 不叫小名而叫全稱,直接調用系統指令winpty tree.com
-
: 假借他人之手,變相調用系統指令winpty cmd //c tree
上文中說設定檔案編碼應該能夠解決中文亂碼問題結果仍然有亂碼,猜測是 bug
,現在沒有打臉吧?
既然已經提供了解決方案,那文章是不是應該到此為止了呢?
不不不,遠遠還沒結束,這隻是開胃小菜,好戲還在後頭呢.
更何況這指令也忒長了,記不住啊!
很簡單,可以設定别名啊,把常用指令設定成别名,這樣就記住啦!
輸入
alias
指令沒有報錯,說明目前環境是支援設定别名的.
snowdreams1006@home MINGW64 /g/sublime/test
$ alias
alias ll='ls -l'
alias ls='ls -F --color=auto --show-control-chars'
alias node='winpty node.exe'
按照
linux
的操作習慣,指令行設定的一般都是臨時性的,想要永久生效,都要寫入到檔案中,别名這種當然要一勞永逸設定成永久檔案.
snowdreams1006@home MINGW64 /g/sublime/test
$ cat /etc/bashrc
cat: /etc/bashrc: No such file or directory
snowdreams1006@home MINGW64 /g/sublime/test
$ cat ~/.bashrc
cat: /c/Users/snowdreams1006/.bashrc: No such file or directory
竟然配置檔案都不存在?
當然不存在了啊!快醒醒,你是在
Windows
系統上并不是
Linux
系統,上哪給你弄這些配置檔案去?
腦海中迅速閃現哲學基本問題: 我是誰,我在那,我在幹什麼?
我是
Windows
系統使用者,正在
git bash
指令行中試圖設定别名,沒有找到類似于
linux
配置檔案.
既然你明白你何出來,那你去那裡看看有沒有什麼發現?
snowdreams1006@home MINGW64 /g/sublime/test
$ cd /e/git
snowdreams1006@home MINGW64 /e/git
$ winpty tree.com
卷 軟體 的檔案夾 PATH 清單
卷序列号為 00000063 223E:7300
E:.
├─bin
├─cmd
├─dev
│ ├─mqueue
│ └─shm
├─etc
│ ├─pkcs11
│ ├─pki
│ │ └─ca-trust
│ │ ├─extracted
│ │ │ ├─java
│ │ │ ├─openssl
│ │ │ └─pem
│ │ └─source
│ │ └─anchors
│ ├─profile.d
│ └─ssh
├─mingw64
│ ├─bin
│ ├─doc
│ │ └─git-credential-manager
│ ├─etc
│ │ ├─pkcs11
│ │ └─pki
│ │ └─ca-trust
│ │ └─extracted
│ │ ├─java
│ │ ├─openssl
│ │ └─pem
│ ├─lib
│ │ ├─dde1.4
│ │ ├─engines
│ │ ├─itcl4.0.4
│ │ ├─p11-kit
│ │ ├─pkcs11
│ │ ├─reg1.3
│ │ ├─sqlite3.11.0
│ │ ├─tcl8
│ │ │ ├─8.4
│ │ │ │ └─platform
│ │ │ ├─8.5
│ │ │ └─8.6
│ │ │ └─tdbc
│ │ ├─tcl8.6
│ │ │ ├─encoding
│ │ │ ├─http1.0
│ │ │ ├─msgs
│ │ │ ├─opt0.4
│ │ │ └─tzdata
│ │ │ ├─Africa
│ │ │ ├─America
│ │ │ │ ├─Argentina
│ │ │ │ ├─Indiana
│ │ │ │ ├─Kentucky
│ │ │ │ └─North_Dakota
│ │ │ ├─Antarctica
│ │ │ ├─Arctic
│ │ │ ├─Asia
│ │ │ ├─Atlantic
│ │ │ ├─Australia
│ │ │ ├─Brazil
│ │ │ ├─Canada
│ │ │ ├─Chile
│ │ │ ├─Etc
│ │ │ ├─Europe
│ │ │ ├─Indian
│ │ │ ├─Mexico
│ │ │ ├─Pacific
│ │ │ ├─SystemV
│ │ │ └─US
│ │ ├─thread2.7.3
│ │ └─tk8.6
│ │ ├─demos
│ │ │ └─images
│ │ ├─images
│ │ ├─msgs
│ │ └─ttk
│ ├─libexec
│ │ └─git-core
│ │ └─mergetools
│ ├─share
│ │ ├─antiword
│ │ ├─doc
│ │ │ ├─connect
│ │ │ ├─git-doc
│ │ │ │ ├─howto
│ │ │ │ └─technical
│ │ │ └─nghttp2
│ │ ├─gettext-0.19.7
│ │ │ └─its
│ │ ├─git
│ │ │ ├─bindimage.txt
│ │ │ └─completion
│ │ ├─git-core
│ │ │ └─templates
│ │ │ ├─hooks
│ │ │ └─info
│ │ ├─git-gui
│ │ │ └─lib
│ │ ├─gitweb
│ │ │ └─static
│ │ ├─licenses
│ │ │ ├─bzip2
│ │ │ ├─expat
│ │ │ ├─gcc-libs
│ │ │ ├─gettext
│ │ │ │ ├─gettext-runtime
│ │ │ │ │ ├─intl
│ │ │ │ │ └─libasprintf
│ │ │ │ ├─gettext-tools
│ │ │ │ │ └─gnulib-lib
│ │ │ │ │ └─libxml
│ │ │ │ └─gnulib-local
│ │ │ │ └─lib
│ │ │ │ └─libxml
│ │ │ ├─libffi
│ │ │ ├─libiconv
│ │ │ │ └─libcharset
│ │ │ ├─libssh2
│ │ │ ├─libsystre
│ │ │ ├─libtasn1
│ │ │ ├─libtre
│ │ │ ├─libwinpthread
│ │ │ │ └─mingw-w64-libraries
│ │ │ │ └─winpthreads
│ │ │ ├─openssl
│ │ │ ├─wineditline
│ │ │ └─zlib
│ │ ├─nghttp2
│ │ ├─p11-kit
│ │ │ └─modules
│ │ ├─perl5
│ │ │ └─site_perl
│ │ │ └─Git
│ │ │ └─SVN
│ │ │ └─Memoize
│ │ └─pki
│ │ └─ca-trust-source
│ └─ssl
│ └─certs
├─tmp
└─usr
├─bin
│ ├─core_perl
│ └─vendor_perl
├─lib
│ ├─awk
│ ├─coreutils
│ ├─gawk
│ ├─gnupg
│ │ └─gnupg
│ ├─openssl
│ │ └─engines
│ ├─p11-kit
│ ├─perl5
│ │ ├─core_perl
│ │ │ ├─auto
│ │ │ │ ├─arybase
│ │ │ │ ├─attributes
│ │ │ │ ├─B
│ │ │ │ ├─Compress
│ │ │ │ │ └─Raw
│ │ │ │ │ ├─Bzip2
│ │ │ │ │ └─Zlib
│ │ │ │ ├─Cwd
│ │ │ │ ├─Data
│ │ │ │ │ └─Dumper
│ │ │ │ ├─DB_File
│ │ │ │ ├─Devel
│ │ │ │ │ ├─Peek
│ │ │ │ │ └─PPPort
│ │ │ │ ├─Digest
│ │ │ │ │ ├─MD5
│ │ │ │ │ └─SHA
│ │ │ │ ├─Encode
│ │ │ │ │ ├─Byte
│ │ │ │ │ ├─CN
│ │ │ │ │ ├─EBCDIC
│ │ │ │ │ ├─JP
│ │ │ │ │ ├─KR
│ │ │ │ │ ├─Symbol
│ │ │ │ │ ├─TW
│ │ │ │ │ └─Unicode
│ │ │ │ ├─Fcntl
│ │ │ │ ├─File
│ │ │ │ │ ├─DosGlob
│ │ │ │ │ └─Glob
│ │ │ │ ├─Filter
│ │ │ │ │ └─Util
│ │ │ │ │ └─Call
│ │ │ │ ├─GDBM_File
│ │ │ │ ├─Hash
│ │ │ │ │ └─Util
│ │ │ │ │ └─FieldHash
│ │ │ │ ├─I18N
│ │ │ │ │ └─Langinfo
│ │ │ │ ├─IO
│ │ │ │ ├─IPC
│ │ │ │ │ └─SysV
│ │ │ │ ├─List
│ │ │ │ │ └─Util
│ │ │ │ ├─Math
│ │ │ │ │ └─BigInt
│ │ │ │ │ └─FastCalc
│ │ │ │ ├─MIME
│ │ │ │ │ └─Base64
│ │ │ │ ├─mro
│ │ │ │ ├─NDBM_File
│ │ │ │ ├─ODBM_File
│ │ │ │ ├─Opcode
│ │ │ │ ├─PerlIO
│ │ │ │ │ ├─encoding
│ │ │ │ │ ├─mmap
│ │ │ │ │ ├─scalar
│ │ │ │ │ └─via
│ │ │ │ ├─POSIX
│ │ │ │ ├─re
│ │ │ │ ├─SDBM_File
│ │ │ │ ├─Socket
│ │ │ │ ├─Storable
│ │ │ │ ├─Sys
│ │ │ │ │ ├─Hostname
│ │ │ │ │ └─Syslog
│ │ │ │ ├─threads
│ │ │ │ │ └─shared
│ │ │ │ ├─Tie
│ │ │ │ │ └─Hash
│ │ │ │ │ └─NamedCapture
│ │ │ │ ├─Time
│ │ │ │ │ ├─HiRes
│ │ │ │ │ └─Piece
│ │ │ │ ├─Unicode
│ │ │ │ │ └─Collate
│ │ │ │ ├─Win32
│ │ │ │ ├─Win32API
│ │ │ │ │ └─File
│ │ │ │ └─Win32CORE
│ │ │ ├─B
│ │ │ ├─Compress
│ │ │ │ └─Raw
│ │ │ ├─CORE
│ │ │ ├─Data
│ │ │ ├─Devel
│ │ │ ├─Digest
│ │ │ ├─Encode
│ │ │ │ ├─CN
│ │ │ │ ├─JP
│ │ │ │ ├─KR
│ │ │ │ ├─MIME
│ │ │ │ │ └─Header
│ │ │ │ └─Unicode
│ │ │ ├─File
│ │ │ │ └─Spec
│ │ │ ├─Filter
│ │ │ │ └─Util
│ │ │ ├─Hash
│ │ │ │ └─Util
│ │ │ ├─I18N
│ │ │ ├─IO
│ │ │ │ └─Socket
│ │ │ ├─IPC
│ │ │ ├─List
│ │ │ │ └─Util
│ │ │ ├─Math
│ │ │ │ └─BigInt
│ │ │ ├─MIME
│ │ │ ├─PerlIO
│ │ │ ├─Scalar
│ │ │ ├─Sub
│ │ │ ├─Sys
│ │ │ ├─threads
│ │ │ ├─Tie
│ │ │ │ └─Hash
│ │ │ ├─Time
│ │ │ ├─Unicode
│ │ │ │ └─Collate
│ │ │ └─Win32API
│ │ └─vendor_perl
│ │ ├─auto
│ │ │ ├─HTML
│ │ │ │ └─Parser
│ │ │ ├─Net
│ │ │ │ └─SSLeay
│ │ │ ├─SVN
│ │ │ │ ├─_Client
│ │ │ │ ├─_Core
│ │ │ │ ├─_Delta
│ │ │ │ ├─_Fs
│ │ │ │ ├─_Ra
│ │ │ │ ├─_Repos
│ │ │ │ └─_Wc
│ │ │ └─Term
│ │ │ └─ReadKey
│ │ ├─HTML
│ │ ├─Net
│ │ │ └─SSLeay
│ │ ├─SVN
│ │ └─Term
│ ├─pkcs11
│ ├─sasl2
│ ├─ssh
│ ├─tar
│ └─terminfo
│ ├─63
│ ├─64
│ └─78
├─libexec
├─share
│ ├─bash-completion
│ │ └─completions
│ ├─cygwin
│ ├─git
│ ├─gnupg
│ ├─licenses
│ │ ├─curl
│ │ ├─dos2unix
│ │ ├─expat
│ │ ├─file
│ │ ├─gcc-libs
│ │ ├─libffi
│ │ ├─libsasl
│ │ ├─libsqlite
│ │ ├─libssh2
│ │ ├─mintty
│ │ ├─ncurses
│ │ ├─openssh
│ │ ├─openssl
│ │ ├─p11-kit
│ │ ├─perl-Net-SSLeay
│ │ ├─perl-TermReadKey
│ │ ├─unzip
│ │ ├─vim
│ │ └─zlib
│ ├─misc
│ ├─p11-kit
│ │ └─modules
│ ├─perl5
│ │ ├─core_perl
│ │ │ ├─App
│ │ │ │ └─Prove
│ │ │ │ └─State
│ │ │ │ └─Result
│ │ │ ├─Archive
│ │ │ │ └─Tar
│ │ │ ├─Attribute
│ │ │ ├─autodie
│ │ │ │ ├─exception
│ │ │ │ └─Scope
│ │ │ ├─B
│ │ │ ├─Carp
│ │ │ ├─Class
│ │ │ ├─Compress
│ │ │ ├─Config
│ │ │ │ └─Perl
│ │ │ ├─CPAN
│ │ │ │ ├─Exception
│ │ │ │ ├─FTP
│ │ │ │ ├─HTTP
│ │ │ │ ├─Kwalify
│ │ │ │ ├─LWP
│ │ │ │ ├─Meta
│ │ │ │ └─Plugin
│ │ │ ├─DBM_Filter
│ │ │ ├─Devel
│ │ │ ├─Digest
│ │ │ ├─Encode
│ │ │ ├─encoding
│ │ │ ├─Exporter
│ │ │ ├─ExtUtils
│ │ │ │ ├─CBuilder
│ │ │ │ │ └─Platform
│ │ │ │ │ └─Windows
│ │ │ │ ├─Command
│ │ │ │ ├─Constant
│ │ │ │ ├─Liblist
│ │ │ │ ├─MakeMaker
│ │ │ │ │ └─version
│ │ │ │ ├─ParseXS
│ │ │ │ └─Typemaps
│ │ │ ├─File
│ │ │ ├─Filter
│ │ │ ├─Getopt
│ │ │ ├─HTTP
│ │ │ ├─I18N
│ │ │ │ └─LangTags
│ │ │ ├─IO
│ │ │ │ ├─Compress
│ │ │ │ │ ├─Adapter
│ │ │ │ │ ├─Base
│ │ │ │ │ ├─Gzip
│ │ │ │ │ ├─Zip
│ │ │ │ │ └─Zlib
│ │ │ │ ├─Socket
│ │ │ │ └─Uncompress
│ │ │ │ └─Adapter
│ │ │ ├─IPC
│ │ │ ├─JSON
│ │ │ │ └─PP
│ │ │ ├─Locale
│ │ │ │ ├─Codes
│ │ │ │ └─Maketext
│ │ │ ├─Math
│ │ │ │ ├─BigFloat
│ │ │ │ └─BigInt
│ │ │ ├─Memoize
│ │ │ ├─Module
│ │ │ │ ├─CoreList
│ │ │ │ └─Load
│ │ │ ├─Net
│ │ │ │ └─FTP
│ │ │ ├─overload
│ │ │ ├─Params
│ │ │ ├─Parse
│ │ │ │ └─CPAN
│ │ │ ├─Perl
│ │ │ ├─PerlIO
│ │ │ │ └─via
│ │ │ ├─Pod
│ │ │ │ ├─Perldoc
│ │ │ │ ├─Simple
│ │ │ │ └─Text
│ │ │ ├─Search
│ │ │ ├─TAP
│ │ │ │ ├─Formatter
│ │ │ │ │ ├─Console
│ │ │ │ │ └─File
│ │ │ │ ├─Harness
│ │ │ │ └─Parser
│ │ │ │ ├─Iterator
│ │ │ │ ├─Result
│ │ │ │ ├─Scheduler
│ │ │ │ ├─SourceHandler
│ │ │ │ └─YAMLish
│ │ │ ├─Term
│ │ │ ├─Test
│ │ │ │ ├─Builder
│ │ │ │ │ ├─IO
│ │ │ │ │ └─Tester
│ │ │ │ ├─Tester
│ │ │ │ └─use
│ │ │ ├─Text
│ │ │ ├─Thread
│ │ │ ├─Tie
│ │ │ ├─Time
│ │ │ ├─Unicode
│ │ │ │ └─Collate
│ │ │ │ └─CJK
│ │ │ ├─unicore
│ │ │ │ ├─lib
│ │ │ │ │ ├─Age
│ │ │ │ │ ├─Alpha
│ │ │ │ │ ├─Bc
│ │ │ │ │ ├─BidiC
│ │ │ │ │ ├─BidiM
│ │ │ │ │ ├─Blk
│ │ │ │ │ ├─Bpt
│ │ │ │ │ ├─Cased
│ │ │ │ │ ├─Ccc
│ │ │ │ │ ├─CE
│ │ │ │ │ ├─CI
│ │ │ │ │ ├─CompEx
│ │ │ │ │ ├─CWCF
│ │ │ │ │ ├─CWCM
│ │ │ │ │ ├─CWKCF
│ │ │ │ │ ├─CWL
│ │ │ │ │ ├─CWT
│ │ │ │ │ ├─CWU
│ │ │ │ │ ├─Dash
│ │ │ │ │ ├─Dep
│ │ │ │ │ ├─DI
│ │ │ │ │ ├─Dia
│ │ │ │ │ ├─Dt
│ │ │ │ │ ├─Ea
│ │ │ │ │ ├─Ext
│ │ │ │ │ ├─Gc
│ │ │ │ │ ├─GCB
│ │ │ │ │ ├─GrBase
│ │ │ │ │ ├─Hex
│ │ │ │ │ ├─Hst
│ │ │ │ │ ├─Hyphen
│ │ │ │ │ ├─IDC
│ │ │ │ │ ├─Ideo
│ │ │ │ │ ├─IDS
│ │ │ │ │ ├─In
│ │ │ │ │ ├─Jg
│ │ │ │ │ ├─Jt
│ │ │ │ │ ├─Lb
│ │ │ │ │ ├─LOE
│ │ │ │ │ ├─Lower
│ │ │ │ │ ├─Math
│ │ │ │ │ ├─NChar
│ │ │ │ │ ├─NFCQC
│ │ │ │ │ ├─NFDQC
│ │ │ │ │ ├─NFKCQC
│ │ │ │ │ ├─NFKDQC
│ │ │ │ │ ├─Nt
│ │ │ │ │ ├─Nv
│ │ │ │ │ ├─PatSyn
│ │ │ │ │ ├─PatWS
│ │ │ │ │ ├─Perl
│ │ │ │ │ ├─QMark
│ │ │ │ │ ├─SB
│ │ │ │ │ ├─Sc
│ │ │ │ │ ├─Scx
│ │ │ │ │ ├─SD
│ │ │ │ │ ├─STerm
│ │ │ │ │ ├─Term
│ │ │ │ │ ├─UIdeo
│ │ │ │ │ ├─Upper
│ │ │ │ │ ├─WB
│ │ │ │ │ ├─XIDC
│ │ │ │ │ └─XIDS
│ │ │ │ └─To
│ │ │ ├─User
│ │ │ ├─version
│ │ │ ├─warnings
│ │ │ └─Win32API
│ │ │ └─File
│ │ └─vendor_perl
│ │ ├─Authen
│ │ │ └─SASL
│ │ │ └─Perl
│ │ ├─Convert
│ │ ├─Date
│ │ │ └─Language
│ │ ├─Encode
│ │ ├─Error
│ │ ├─File
│ │ ├─HTML
│ │ ├─HTTP
│ │ │ ├─Cookies
│ │ │ ├─Headers
│ │ │ └─Request
│ │ ├─IO
│ │ │ └─Socket
│ │ │ └─SSL
│ │ ├─LWP
│ │ │ ├─Authen
│ │ │ └─Protocol
│ │ ├─Mail
│ │ │ ├─Field
│ │ │ └─Mailer
│ │ ├─MIME
│ │ │ ├─Decoder
│ │ │ ├─Field
│ │ │ └─Parser
│ │ ├─Net
│ │ │ ├─HTTP
│ │ │ └─SMTP
│ │ ├─Time
│ │ ├─URI
│ │ │ ├─file
│ │ │ └─urn
│ │ └─WWW
│ │ └─RobotRules
│ ├─pki
│ │ └─ca-trust-source
│ ├─tabset
│ ├─terminfo
│ │ ├─63
│ │ ├─64
│ │ └─78
│ └─vim
│ └─vim74
│ ├─autoload
│ │ └─xml
│ ├─colors
│ ├─compiler
│ ├─doc
│ ├─ftplugin
│ ├─indent
│ ├─keymap
│ ├─macros
│ │ ├─hanoi
│ │ ├─life
│ │ ├─maze
│ │ └─urm
│ ├─pack
│ │ └─dist
│ │ └─opt
│ │ ├─dvorak
│ │ │ ├─dvorak
│ │ │ └─plugin
│ │ ├─editexisting
│ │ │ └─plugin
│ │ ├─justify
│ │ │ └─plugin
│ │ ├─matchit
│ │ │ ├─doc
│ │ │ └─plugin
│ │ ├─shellmenu
│ │ │ └─plugin
│ │ └─swapmouse
│ │ └─plugin
│ ├─plugin
│ ├─print
│ ├─spell
│ ├─syntax
│ ├─tools
│ └─tutor
└─ssl
├─certs
└─misc
看到熟悉的
./etc/bash.bashrc
檔案,頓時親切不少,設定一下别名再說.
snowdreams1006@home MINGW64 /e/git
$ echo "# Set alias for tree command" >> ./etc/bash.bashrc
snowdreams1006@home MINGW64 /e/git
$ echo "alias tree='winpty tree.com'" >> ./etc/bash.bashrc
snowdreams1006@home MINGW64 /e/git
$ source ./etc/bash.bashrc
現在測試一下能否正确列印出目錄樹:
snowdreams1006@home MINGW64 /e/git
$ cd /g/sublime/test
snowdreams1006@home MINGW64 /g/sublime/test
$ tree
卷 工作 的檔案夾 PATH 清單
卷序列号為 000000A3 CC3C:50D0
G:.
├─cmd
└─git
親測有效,通過設定别名的方式可以簡化指令,進而實作在
git bash
中優雅調用
tree
固執少年一意孤行
少年既然不聽勸,那我隻好和你一起一意孤行.
git bash
不支援
tree
指令,意味着
mintty
終端不支援
tree
指令,但
mintty
既然作為一款優秀的終端模拟器不可能不支援
tree
指令,否則
cygwin
msys2
mingw
等系統不可能将其作為預設終端.
回想起
linux
系統,最小化安裝版也不支援
tree
指令,通過包管理工具自行擴充即可支援
tree
是以,思路有兩種,像
linux
那樣通過包管理工具安裝
tree
指令,或者通過源碼編譯方式擴充
tree
第一種需要包管理工具,而
git bash
使用的是
mintty
終端,并沒有提供相應的包管理工具.
是以想要通過包管理工具進行安裝
tree
指令也是無路可走.
包管理工具安裝
如果能夠提供包管理工具,那麼我們就可以像
linux
系統那樣安裝第三方指令一樣,安裝
tree
指令了.
首先想到的是
mintty
官網有沒有相關說明,遺憾的是,
mintty
本身一般是通過包管理工具安裝的,單獨的終端并沒有包管理的環境,是以無法調用相關指令.
Administrator@snowdreams1006 MINGW64 /f/workspace/test
$ mingw-get
bash: mingw-get: command not found
Administrator@snowdreams1006 MINGW64 /f/workspace/test
$ pacman
bash: pacman: command not found
然而,小小的挫折是不會輕易放棄的,既然
mintty
官網不能提供有效的幫助,那我們回到最初安裝
git
的地方,看一下
git
能否提供相關的包管理工具.
頻繁出現
Git For Windows
名詞,根據軟體的指令規則,
Git for Windows
可能是獨立的軟體,更何況
git bash
內建的終端也不是自身研發的終端而是第三方的
mintty
終端.
是以,我們有理由相信
Git for Windows
是另外的團隊在維護,而不是
Git
團隊.
git-for-windows
官網: https://gitforwindows.org/
根據官方說明,安裝後正在下載下傳相關依賴,下載下傳速度比較慢的話,請自行解決.
下載下傳完成後,原來的
cmd
視窗會自動關閉并且打開新的
git bash
視窗.
Administrator@snowdreams1006 MINGW64 / (master)
$ sdk help
The 'sdk' shell function helps you to get up and running
with the Git for Windows SDK. The available subcommands are:
create-desktop-icon: install a desktop icon that starts the Git for
Windows SDK Bash.
cd <project>: initialize/update a worktree and cd into it. Known projects:
git git-extra msys2-runtime installer build-extra
MINGW-packages MSYS2-packages mingw-w64-busybox mingw-w64-curl
mingw-w64-cv2pdb mingw-w64-git mingw-w64-git-credential-manager
mingw-w64-git-lfs mingw-w64-git-sizer mingw-w64-wintoast bash
curl gawk git-flow gnupg heimdal mintty nodejs openssh openssl
perl perl-HTML-Parser perl-Locale-Gettext perl-Net-SSLeay
perl-TermReadKey perl-XML-Parser perl-YAML-Syck subversion tig
init <project>: initialize and/or update a worktree. Known projects
are the same as for the 'cd' command.
build <project>: builds one of the following:
git-and-installer git git-extra msys2-runtime installer
mingw-w64-busybox mingw-w64-curl mingw-w64-cv2pdb mingw-w64-git
mingw-w64-git-credential-manager mingw-w64-git-lfs
mingw-w64-git-sizer mingw-w64-wintoast bash curl gawk
git-flow gnupg heimdal mintty nodejs openssh openssl
perl perl-HTML-Parser perl-Locale-Gettext perl-Net-SSLeay
perl-TermReadKey perl-XML-Parser perl-YAML-Syck subversion tig
edit <file>: edit a well-known file. Well-known files are:
git-sdk.sh sdk.completion ReleaseNotes.md install.iss
reload: reload the 'sdk' function.
現在安裝完成後,我們再次打開
Git for Windows
的開發文檔簡介,從中不難發現該項目使用了
MSYS2
項目,那麼問題迎刃而解.
根據科普知識,我們知道
MSYS2
MinGW
都是作業系統,而
Git For Windows
将兩者結合在一起,預設使用
MSYS2
的包管理工具.
Administrator@snowdreams1006 MINGW64 / (master)
$ Pacman -h
用法: Pacman <操作> [...]
操作:
Pacman {-h --help}
Pacman {-V --version}
Pacman {-D --database} <選項> <軟體包>
Pacman {-F --files} [選項] [軟體包]
Pacman {-Q --query} [選項] [軟體包]
Pacman {-R --remove} [選項] <軟體包>
Pacman {-S --sync} [選項] [軟體包]
Pacman {-T --deptest} [選項] [軟體包]
Pacman {-U --upgrade} [選項] <檔案>
使用 'Pacman {-h --help}' 及某個操作以檢視可用選項
激動人心的時刻就要來臨,在正式使用
Pacman
安裝
tree
指令外,我們再次檢查目前系統環境以確定沒有
git bash
無法調用
tree
Administrator@snowdreams1006 MINGW64 / (master)
$ tree
bash: tree: 未找到指令
Pacman -S tree
指令安裝
tree
Administrator@snowdreams1006 MINGW64 / (master)
$ Pacman -S tree
正在解析依賴關系...
正在查找軟體包沖突...
軟體包 (1) tree-1.8.0-1
下載下傳大小: 0.05 MiB
全部安裝大小: 0.07 MiB
:: 進行安裝嗎? [Y/n] y
警告:沒有 /var/cache/pacman/pkg/ 緩存存在,正在建立...
:: 正在擷取軟體包......
tree-1.8.0-1-x86_64 51.1 KiB 211K/s 00:00 [#####################] 100%
(1/1) 正在檢查密鑰環裡的密鑰 [#####################] 100%
(1/1) 正在檢查軟體包完整性 [#####################] 100%
(1/1) 正在加載軟體封包件 [#####################] 100%
(1/1) 正在檢查檔案沖突 [#####################] 100%
(1/1) 正在檢查可用存儲空間 [#####################] 100%
:: 正在處理軟體包的變化...
(1/1) 正在安裝 tree
驗證安裝成功,切換到測試目錄調用
tree
指令真的列印出了目錄樹結構.
Administrator@snowdreams1006 MINGW64 / (master)
$ pwd
/
Administrator@snowdreams1006 MINGW64 / (master)
$ cd /f/workspace/test
Administrator@snowdreams1006 MINGW64 /f/workspace/test
$ tree
.
├── cmd
└── gitbash
2 directories, 0 files
tree.exe
檔案确實已經存在,通過這樣方式當然可以安裝任意第三方指令了呢!
Administrator@snowdreams1006 MINGW64 / (master)
$ pwd
/
Administrator@snowdreams1006 MINGW64 / (master)
$ ls usr/bin/tree.exe
usr/bin/tree.exe*
Administrator@snowdreams1006 MINGW64 / (master)
$ ls usr/bin/tree.exe
usr/bin/tree.exe*
然而,事情還沒有結束,雖然列印目前路徑顯示的是在
/
,但是如果從普通的
git bash
指令行視窗進入
/
,發現他們并不一緻!
開發版左上角文字:,普通版左上角:
SDK-64
MinGW64
事情應該不至于這麼複雜,我猜測如果進入到
git sdk
的安裝目錄,應該是一樣的!
源碼編譯安裝
還有一種源碼編譯安裝方式,可以猜想到的是将會比較麻煩,不僅要安裝
c
編譯環境,還可能會面臨如何移植到
Windows
環境的問題.
恕再下先行一步,告辭!
但是老司機怎麼能收走就走,不是說好一起闖天下得嘛?
然而,心有餘而力不足,編譯安裝再到測試确實是不少挑戰,最重要的是,電腦太卡了等不了.
是以,收集到了一些資料友善有條件的小夥伴去研究吧!
下載下傳連結: ftp://mama.indstate.edu/linux/tree/tree-1.8.0.tgz
-
mingw
msys2
系統上編譯安裝cygwin
tree
檔案,最終生成c
可執行檔案.tree.exe
- 獨立安裝
編譯環境,生成的c
可執行檔案再想辦法相容到tree.exe
所支援的git bash
類型,或許也不用轉換..exe
- 請參考
系統的linux
指令源碼: http://mama.indstate.edu/users/ice/tree/tree
我覺得我還可以再堅持一會,雖然不能從頭開始編譯生成
tree.exe
可執行檔案,但是研究了這麼多朋友圈關系,足夠我找到解決方案了.
tree
指令的源碼檔案編譯成
tree.exe
可執行檔案比較費勁,但是可以找到已經編譯好的檔案啊.
說道這裡,不得不提一下神奇的 sourceforge 網站,提供源碼和下載下傳網站.
前面我們一直在說
mintty
終端模拟器也好,或者
mingw
msys2
cygwin
作業系統也罷,他們或多或少和
GNU
有一些聯系,而
GNU
是自由軟體作業系統,源碼會随程式一同釋出.
是以我們應該可以從
sourceforge
網站上找到些蛛絲馬迹,說不定還有打包好的可執行檔案呢,如果那樣的話就不用我們手動編譯安裝了!
功夫不負有心人,竟然真的找到了,搜尋
GNU
發現了
gnuwin32
項目,完整提供了原生指令,其中就有我們需要的
tree
下載下傳連結: https://sourceforge.net/projects/gnuwin32/files/tree/1.5.2.2/tree-1.5.2.2-bin.zip/download
于是下載下傳二進制檔案找到其中的
/bin/tree.exe
并将其複制到
/git/usr/bin
目錄下,這樣
git bash
本身就支援
tree
首先清除掉上一步設定的别名,防止幹擾以確定此二進制檔案真實有效.
snowdreams1006@home MINGW64 /g/sublime/test
# 切換到 `git` 安裝目錄
$ cd /e/git
snowdreams1006@home MINGW64 /e/git
# 編輯 `bash.bashrc` 配置檔案,移除别名
$ vim ./etc/bash.bashrc
snowdreams1006@home MINGW64 /e/git
# 檢視配置檔案内容,别名設定已移除
$ tail ./etc/bash.bashrc
[[ "$-" != *i* ]] && return
# Set a default prompt of: user@host, MSYSTEM variable, and current_directory
#PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '
# Uncomment to use the terminal colours set in DIR_COLORS
# eval "$(dircolors -b /etc/DIR_COLORS)"
# Fixup git-bash in non login env
shopt -q login_shell || . /etc/profile.d/git-prompt.sh
snowdreams1006@home MINGW64 /e/git
# 重新整理配置檔案,使其立即生效
$ source ./etc/bash.bashrc
snowdreams1006@home MINGW64 /e/git
# 移除 `tree` 别名,适用于指令行方式設定而不是檔案設定
$ unalias tree
snowdreams1006@home MINGW64 /e/git
# 運作 `tree` 指令,確定已經無法通過别名方式調用系統的 `tree.com` 指令
$ tree
bash: tree: command not found
真的成功添加了
tree.exe
指令,明顯和
cmd
自帶的
tree.com
指令不一緻.
snowdreams1006@home MINGW64 /e/git
$ cd /g/sublime/test
snowdreams1006@home MINGW64 /g/sublime/test
# 擴充指令 `tree` 幫助資訊
$ tree.exe --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
[--filelimit #] [<directory list>]
-a All files are listed.
-d List directories only.
-l Follow symbolic links like directories.
-f Print the full path prefix for each file.
-i Don't print indentation lines.
-q Print non-printable characters as '?'.
-N Print non-printable characters as is.
-p Print the protections for each file.
-u Displays file owner or UID number.
-g Displays file group owner or GID number.
-s Print the size in bytes of each file.
-h Print the size in a more human readable way.
-D Print the date of last modification.
-F Appends '/', '=', '*', or '|' as per ls -F.
-v Sort files alphanumerically by version.
-r Sort files in reverse alphanumeric order.
-t Sort files by last modification time.
-x Stay on current filesystem only.
-L level Descend only level directories deep.
-A Print ANSI lines graphic indentation lines.
-S Print with ASCII graphics indentation lines.
-n Turn colorization off always (-C overrides).
-C Turn colorization on always.
-P pattern List only those files that match the pattern given.
-I pattern Do not list files that match the given pattern.
-H baseHREF Prints out HTML format with baseHREF as top directory.
-T string Replace the default HTML title and H1 header with string.
-R Rerun tree when max dir level reached.
-o file Output to file instead of stdout.
--inodes Print inode number of each file.
--device Print device ID number to which each file belongs.
--noreport Turn off file/directory count at end of tree listing.
--nolinks Turn off hyperlinks in HTML output.
--dirsfirst List directories before files.
--charset X Use charset X for HTML and indentation line output.
--filelimit # Do not descend dirs with more than # files in them.
snowdreams1006@home MINGW64 /g/sublime/test
# 原生 `tree.com` 幫助資訊
$ winpty tree.com /?
卷 軟體 的檔案夾 PATH 清單
卷序列号為 000000CA 223E:7300
E:\GIT\?
無效的路徑 - \GIT\?
沒有子檔案夾
雖然原生
cmd
tree.com
指令也能列印出目錄結構樹,但是和擴充的第三方
tree.exe
指令相比,可配置的選項實在太少,難怪固執少年會執意擴充
tree
懶人直達
如果想要在
git bash
指令行中調用
tree
指令,總結了下列幾種方法.
注意: 從上到下逐漸複雜,根據自己的情況自行選擇.
-
: 直接調用winpty tree.com
内置cmd
tree.com
-
: 通知winpty cmd //c tree
cmd
tree
-
開發版,Git For Windows
Pacman -S tree
指令,然後執行tree
調用.tree
- 下載下傳 已編譯好的
檔案到tree.exe
安裝目錄下的git bash
目錄,然後執行/usr/bin
tree
回顧總結
Git
本身并不支援
Windows
系統,
Git For Windows
團隊為了移植到
Windows
平台,付出了很多努力,最直覺的感受就是提供了
Git For Windows
軟體.
由于
Git for Windows
的出色工作得到
Git
的官方認可,現在預設下載下傳的
Git
就是來源于
Git for Windows
但
Git
底層是運作在類
linux
系統的,這種差異必然需要
Windows
到
Linux
的中間處理層進行轉換.
是以,
Git for Window
背後的技術中涉及到大量的
GNU
自由軟體作業系統和
WSL
(
Windows Subsystem for Linux
) 的相關代碼.
正是由于背後千絲萬縷的聯系,為我們擴充
git bash
指令行提供了一些思路.
基于
Cygwin
系統進行擴充,安裝完整的作業系統,模拟出
linux
運作環境,在
Windows
上也能找到
linux
的感覺.
當然,
Cygwin
由于比較完整,體積也相當大,是以在此衍生出
MSYS2
MinGW
殊途同歸,他們的底層架構有些不同,但目的是一緻的,都是在
Windows
上找到
Linux
的感覺,并且他們的終端指令行幾乎都是
mintty
在終端中調用各自的包管理工具即可輕松擴充第三方指令,此外,由于他們大多數都有
c
編譯環境,是以也可以選擇重新編譯安裝.
git bash
指令行看起來下像是
git
官方支援,其實卻是由
Git for Windows
組織獨立維護的開源項目.
預設
Git for Windows
沒有提供包管理工具,開發版卻預設內建了
MSYS2
環境.也就是說我們可以用
Pacman
來安裝
tree
最後稍微總結本文知識要點:
-
指令行并不能完全替代git bash
指令,兩者互補才能相得益彰.cmd
-
git bash
程式需要通過cmd
調用,比如winpty
winpty tree.com
-
預設安裝程式無包管理工具等進階功能,如需擴充自定義指令應該下載下傳git bash
Git for Windows SDK
-
環境相容git bash
MSYS2
MinGW
等系列自由軟體,其他類似系統的Cygwin
可能并不支援.tree.exe
好了,說了這麼多,小夥伴們 get 到如何在
git bash
使用(擴充)
tree
指令了嗎?
如有疑問,歡迎留言告訴我!