平时干活一个 git-bash 就够了,支持常用的 vim、shell、ssh 等工具,有时需要格式化目录列表,git-bash 下缺一个 tree 命令。之前在 mingw 环境找过平替,但还是没有 windows 下编译好的原生 exe 兼容性好。也试过 Rust 版的 exa ,编译时提示不支持 windows。
今天在 github 上找到一个 go 版本的 tree 命令,才发现跨平台还是 Go-Lang 强。go-tree 的 github 项目地址为:
https://github.com/ibrahimaydinnet/go-tree
先安装 go 安装包,安装完后程序会自动注册环境变量。
在命令行执行 go-tree 的安装命令:
C:\> go install github.com/ibrahimaydinnet/go-tree@latest
go: downloading github.com/ibrahimaydinnet/go-tree v1.1.0
go: downloading github.com/spf13/cobra v1.0.0
go: downloading github.com/mattn/go-colorable v0.1.6
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/spf13/pflag v1.0.3
go: downloading github.com/inconshreveable/mousetrap v1.0.0
最终 go-tree.exe 会安装至 %GOPATH%/bin 目录:
d:\Go> where go-tree.exe
C:\Users\Administrator\go\bin\go-tree.exe
将 go-tree 所在目录加到 git-bash 的 PATH 环境变量中,然后就可以使用了。
go-tree 模拟了 tree 命令的输出 :
同时 go-tree 支持带颜色输出,选项为 -c
同时还额外支持只输出目录,不显示文件,选项为 -j
当然也支持限制目录级别,选项为 -l n
在 Windows 下目录会加一个反斜杠,如果不想要可以用 sed 去掉,命令为:
$ go-tree -c -j -l 2 | sed 's#\\##g'
.
└── 证明材料
├── 01基础条件
├── 02技术队伍
├── 03信息化服务能力
├── 04信息安全管理
├── 05信息化建设水平与效益
└── 06创新能力
全文完。
如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。
文章转载自生有可恋,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。