[ Content contribution] 自荐一个类似exa的命令行 ls 工具
Tofloor
poster avatar
Equationzhao
deepin
2023-09-08 10:32
Author

g: Yet another ls

项目地址

go 写的 , 跨平台 ls

主要是因为exa好像没有官方的Windows release, 我又想在几台电脑上都用类似的工具, 于是就自己写了一个(不过写了几个初版之后发现lsd也是跨平台的,但是都写了就继续完善吧 😕 😂)

支持多种输出格式 across / vertical / commas / table / markdown / json / html / csv / tree ...

支持自定义主题,支持在 build 时直接嵌入自定义主题

支持更多的输出内容 比如 checksum (md5/sha1/sha256...) , mime-type ,

支持丰富的sort选项和filter选项

支持生成替换shell原生ls的脚本 (zsh/bash/fish/nushell/powershell) 下面的示例就把原生的ls替换了

对于支持的shell 会自动在文件上添加超链接, 自动检测终端对颜色的支持 (basic|256|24bit) 【均可修改默认配置】

更多配置请参考 GitHub 和 项目文档 Start - g - a powerful ls (equationzhao.space)

示例

  1. tree view + 显示隐藏文件 + git status + 不显示在gitignore中的文件 + 忽略 .git

  1. 列出size前5的文件
    image.png

  2. 按table格式输出 (这个格式是从 nushell 里'偷的')

    image.png

  3. 显示超链接

    image.png

安装

From source

go version required >= 1.21

go install -ldflags="-s -w"  github.com/Equationzhao/g@latest

用 archlinux的小伙伴可以从aur安装

yay -S g-ls

mac homebrew:

brew install g-ls

或者下面用自己建的 brew-tap:

brew tap equationzhao/core git@github.com:Equationzhao/homebrew-g.git
brew install g-ls

或者手动下载编译好的文件添加到 path -> Releases · Equationzhao/g (github.com)

目前已经提供 deb

性能

没有严谨的测试过,但是Windows下应该比lsd快,Linux/macOS 就被lsd 和 exa 吊打了

不过测试也就图一乐

image.png

image.png

缺点

用的是 urfave/cli 这个框架,不如 cobra 来得那么标准,以后有机会做个迁移

有时候对齐还是有 bug,有可能是一些字符宽度错了,用的库是 https://github.com/mattn/go-runewidth 可能有些字符错了(提了issue但是作者没回 :-(

还有一些拓展名,其实有些不同文件拓展名是一样的,比如 mod 文件可能是音频文件,也可能是 go项目里的 go.mod 这时候如果设置了 mod 后缀的 图标,就会展示错了

还有就是 go 编译的二进制文件自带 runtime, 体积比较大 -> 16.4 MB/11.5 MB (默认build/使用 ldflag '-w -s')

可以尝试用 upx 减小二进制文件大小 -> 4.0 MB

END

最后 欢迎 issue && star

Reply Favorite View the author
All Replies
阿尼樱奈奈
Moderator
2023-09-08 14:36
#1

like

Reply View the author
longlong
deepin
Developer
2023-09-08 16:33
#2

可以尝试打包进入23软件源,不过go最大的问题就是依赖太杂了

Reply View the author
dgmenghuan
deepin
2023-09-08 16:46
#3

ls和以前dir很像,怎么操作实现上面的方法告知一下哈

Reply View the author
longlong
deepin
Developer
2023-09-08 17:50
#4
dgmenghuan

ls和以前dir很像,怎么操作实现上面的方法告知一下哈

ls -la

Reply View the author
Equationzhao
deepin
2023-09-09 23:12
#5
longlong

可以尝试打包进入23软件源,不过go最大的问题就是依赖太杂了

deb 包吗

Reply View the author
dgmenghuan
deepin
2023-09-11 17:37
#6

用python做一个有木有

Reply View the author
Equationzhao
deepin
2023-09-12 01:28
#7
dgmenghuan

用python做一个有木有

有人用 python 做过类似的项目 pls

但是我测试下来确实有点慢

Reply View the author
oncemore
deepin
2023-09-13 05:57
#8

https://github.com/lsd-rs/lsd

和exa一样也是Rust写的,跨平台。

Reply View the author
Equationzhao
deepin
2023-09-13 10:55
#9
oncemore

https://github.com/lsd-rs/lsd

和exa一样也是Rust写的,跨平台。

文章里提到了,我后面才发现 lsd 😂

现在 exa 转到 eza 之后也有 Windows 版本了

Reply View the author
pangqiangqiang
deepin
2023-09-21 18:48
#10

请问大佬们 为什么一片绿油油啊。用xshell就不会呢
image.png

Reply View the author
.(柯南)
deepin
2023-10-07 23:20
#11

牛啊

Reply View the author
魔法师
deepin
2023-10-25 01:26
#12

花哩呼哨
tail

Reply View the author