Linux 命令行工具

介绍


命令行工具

概览

lsd、ripgrep、sd、bat、git-delta、gitui 等由 Rust 编写的 CLI 均可通过 cargo / bin / stew 工具进行安装

系统相关


Markdown 相关


文件相关


编程相关

  • 命令纠正:thefuck

  • 统计代码行数:cloc

  • 统计目录中的代码行数:scc(类似 cloc)


图片相关


其他

  • sshx:通过链接共享终端(可创建多个终端画布)

  • sshs:使用 ~/.ssh/config 列出和连接 hosts

  • zenta 🧘‍♂️:快速恢复专注

  • 富文本:rich

  • 字符 logo 制作:figlet、toilet:Linux 运维相关 — OnlineNote latest documentation

  • 文本编辑器(类似 Vim):helix

  • 趣味小工具

    • cowsay(牛说)
    • sl(火车)
    • fortune(幸运饼干;格言)
    • lolcat
    • boxes
    • cmatrix(黑客帝国类似的矩阵效果)
    • asciiquarium(水族馆)

具体使用

1
2
3
4
5
# 搜索整个 apt package;回车安装
apt-cache search '' | sort | cut --delimiter ' ' --fields 1 | fzf --multi --cycle --reverse --preview-window=right:70%:wrap --preview 'apt-cache show {1}' | xargs -r sudo apt install -y

# 用 bat 作为 previewer
fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"
  • 用 fzf-tab 替代 zsh 的自动补全:GitHub - Aloxaf/fzf-tab
    • 需将 fzf-tab 写在 zsh-autosuggestions、fast-syntax-highlighting 插件前,compinit 后
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 安装
git clone --depth 1 https://github.com/Aloxaf/fzf-tab ${ZSH_CUSTOM}/plugins/fzf-tab

# fzf-tab 配置;写入 ~/.zshrc
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
# NOTE: don't use escape sequences here, fzf-tab will ignore them
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
zstyle ':completion:*' menu no
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# z 安装与配置
git clone https://github.com/rupa/z.git

# 将以下内容添加至 ~/.{bash,zsh}rc
. /path/to/z.sh


# turm 安装
cargo install turm

# peco 安装与使用
brew install peco # 安装

cat file | peco # 基本使用


ncdu -o ncdu.txt # 输出信息到文件中


# navi 使用
navi repo browse # 按需添加 cheatsheet git repo 以增加丰富性


# fzf 安装、升级
# 安装
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
# 升级
cd ~/.fzf && git pull && ./install


# rg 使用
# -g 过滤搜索
rg 'content' -g '!docs/' # 排除
rg 'content' -g '*.py' # 包含


# ripgrep-all 安装与使用
brew install pandoc poppler ffmpeg # 需提前安装
brew install rga

rga 'XXX' file.pdf # 使用;文件后缀可以是 docx、zip、epub 等

# 与 fzf 集成;写入 ~/.{bash,zsh}rc 中
rga-fzf() {
RG_PREFIX="rga --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
xdg-open "$file"
}


# eg 安装
pip install -U eg
brew install eg-examples


# figlet toilet 相关用法
showfigfonts # 查看可用字体
figlet spt # 生成字符 logo
figlet -c spt # 居中
figlet spt | toilet -f term --gay # 彩色输出


# mcfly 安装与配置
brew install mcfly # macOS
# Linux/macOS
curl -LSfs https://raw.githubusercontent.com/cantino/mcfly/master/ci/install.sh | sh -s -- --git cantino/mcfly

eval "$(mcfly init zsh)" # 配置


# fastfetch Ubuntu 安装
sudo add-apt-repository ppa:zhangsongcui3371/fastfetch
sudo apt update

sudo apt install fastfetch


# starship
# 安装
curl -sS https://starship.rs/install.sh | sh # Linux
brew install starship # macOS

# 配置
eval "$(starship init zsh)" # zsh
eval "$(starship init bash)" # bash
Invoke-Expression (&starship init powershell) # PowerShell


# rename 文件重命名
brew install rename
sudo apt install rename


# primitive 安装与使用
go install github.com/fogleman/primitive@latest

export PATH=$(go env GOPATH)/bin:$PATH

primitive -i input.png -o output.png -n 100


# mdq 使用
car *.md | mdq '# title'


# yazi 配置 ~/.config/yazi/yazi.toml
[mgr]
ratio = [ 2, 2, 4 ] # 父目录,当前路径,预览三者之间的比例

[preview]
max_width = 1000
image_quality = 90

[tasks]
image_bound = [ 0, 0 ] # 0 表示不限制图片的大小


# 实用 yazi 插件 ~/.config/yazi/keymap.toml
git clone https://github.com/DreamMaoMao/easyjump.yazi.git ~/.config/yazi/plugins/easyjump.yazi
git clone https://github.com/DreamMaoMao/searchjump.yazi.git ~/.config/yazi/plugins/searchjump.yazi

[[mgr.prepend_keymap]]
on = [ "e" ]
run = "plugin easyjump"
desc = "easyjump"

[[mgr.prepend_keymap]]
on = [ "i" ]
run = "plugin searchjump"
desc = "searchjump mode"