Rust Easy!现代跨平台命令行工具,为您的终端提供动力

1,379 阅读19分钟

Rust is taking over the terminal. Rust is a general-purpose programming language that is blazing fast and memory safe. It is the fastest-growing and most loved programming language in the world. It is used to build everything from operating systems to web servers to command-line tools. Recently there has been a surge of command line tools and utilities written in Rust, and many of them are intended to replace standard Unix commands. They are faster, more user-friendly, and have more features than their standard Unix counterparts. In this post, I will cover some of the best Rust command line tools I have used for a while. You can also use these to supercharge your terminal.

【Rust正在接管终端。Rust是一种通用编程语言,速度快,内存安全。它是世界上增长最快、最受欢迎的编程语言。它用于构建从操作系统到Web服务器到命令行工具的所有内容。最近,用Rust编写的命令行工具和实用程序激增,其中许多旨在取代标准的Unix命令。它们比标准的Unix命令更快、更友好,并且具有更多功能。在这篇文章中,我将介绍一些我使用了一段时间的最佳Rust命令行工具。您也可以使用这些工具来增强您的终端。】

These tools are available for both Linux and macOS. I have not tested them on Windows, but most should also work on Windows. I recommend aliasing the commands to replace the standard commands based on your preferences. If you have Cargo, the rust package manager, you can install all these using Cargo.

【这些工具可用于Linux和macOS。我没有在Windows上测试过它们,但大多数应该也可以在Windows上运行。我建议根据您的偏好将这些命令别名为替换标准命令。如果您有rust包管理器Cargo,您可以使用Cargo安装所有这些工具。】

Alacritty

Let us start with the terminal itself. Alacritty is a cross-platform modern terminal emulator with sensible defaults. It is GPU accelerated, super fast, and highly configurable. You can use it on Linux, macOS, and Windows. It doesn’t have much in terms of a UI, and hence all configurations are done through YAML files. I don’t use it as my primary terminal as I love Yakuake too much for all its cool features. We can get most of those features (tabs, split panes, dropdown mode) using tmux and tdrop if really needed. I use Alacrity when I need speed and GPU acceleration. There is an excellent tutorial on using Alacritty with tmux. You could also use Zellij, a modern terminal multiplexer written in Rust, with Alacritty.

【让我们从终端本身开始。Alacritty是一个跨平台的现代终端仿真器,具有合理的默认值。它是GPU加速的,速度非常快,并且高度可配置。您可以在Linux、macOS和Windows上使用它。它在UI方面没有太多内容,因此所有配置都是通过YAML文件完成的。我没有将它用作我的主终端,因为我太喜欢Yakuake的所有酷功能了。如果确实需要,我们可以使用tmux和tdrop获得大部分功能(选项卡、分割窗格、下拉模式)。当我需要速度和GPU加速时,我会使用Alacrity。有一篇关于在tmux中使用Alacritty的优秀教程。您也可以在Alacritty中使用Zellij,这是一种用Rust编写的现代终端多路复用器。】

There is also the Warp terminal, but it is not open source. It is a great terminal, but I prefer open source software. Thanks to Fran Sancisco for the suggestion.

【还有Warp终端,但它不是开源的。这是一个很棒的终端,但我更喜欢开源软件。感谢Fran Sancisco的建议。】

Installation

# Arch Linux
yay -S alacritty
# Fedora/CentOS
dnf copr enable atim/alacritty
dnf install alacritty
# Debian/Ubuntu
add-apt-repository ppa:aslatter/ppa
apt install alacritty
# macOS Homebrew
brew install --cask alacritty
# Windows Scoop
scoop bucket add extras
scoop install alacritty
# Cargo on any
cargo install alacritty

Starship

Starship is the best terminal prompt I have ever used. Forget Oh My Zsh and stuff like that. Starship is fast, highly customizable, and has a great default theme and settings. I didn’t even change most of the default settings, as things were perfect as it is. Starship works on shells like zsh, fish, and bash and can also work alongside other prompts like Oh My Zsh, in case you still want to use Oh My Zsh for other plugins like autosuggestions and so on. Starship works best with a Nerd Font as it can show icons and ligatures based on context. I used Oh My Zsh for many years with the powerlevel10k theme, but the prompt was a bit slow. Starship is blazing fast with more features and an excellent UX.

【Starship是我使用过的最好的终端提示符。忘记Oh My Zsh之类的东西吧。Starship速度快,高度可定制,并且具有出色的默认主题和设置。我甚至没有更改大多数默认设置,因为事情本身就很完美。Starship可以在像zsh、fish和bash这样的shell上运行,也可以与其他提示符(如Oh My Zsh)一起使用,以防您仍然想使用Oh My Zsh来运行其他插件,如自动建议等。Starship最适合与Nerd Font一起使用,因为它可以根据上下文显示图标和连字。我使用带有powerlevel10k主题的Oh My Zsh多年,但提示有点慢。Starship速度非常快,具有更多功能和出色的用户体验。】

Installation

# Arch Linux
yay -S starship
# Fedora/CentOS
dnf install starship
# Debian/Ubuntu
curl -sS https://starship.rs/install.sh | sh
# macOS/Linux Homebrew
brew install starship
# macOS MacPorts
port install starship
# Windows Scoop
scoop install starship
# Cargo
cargo install starship --locked

bat

bat is one of my favorite tools from this list. It’s a replacement for cat, and once you have used bat, you will never go back. It provides features like syntax highlight, line numbers, Git change highlight, shows special chars, paging, and so on. It is super fast and looks beautiful. I have aliased cat to bat immediately after trying it for the first time. By default, bat behaves similarly to less by paging large output, but that can be disabled to make it work precisely like cat. It can be used as a drop-in replacement for cat even in scripts. bat can also be used as a previewer for fzf. It can also be combined with many other commands and tools like tail, man, and git, among others, to add syntax highlighting to outputs. Syntax highlighting themes are configurable.

【bat是我在此列表中最喜欢的工具之一。它是cat的替代品,一旦您使用过bat,您将永远不会回头。它提供了诸如语法高亮、行号、Git更改高亮、显示特殊字符、分页等功能。它速度超快,看起来很漂亮。我第一次尝试后,立即将cat别名为bat。默认情况下,bat的行为类似于less,通过分页大量输出来实现,但可以禁用它,使其工作方式与cat完全相同。它甚至可以在脚本中用作cat的替代品。bat也可以用作fzf的预览器。它还可以与许多其他命令和工具(如tail、man和git等)结合使用,以向输出添加语法高亮。语法高亮主题是可配置的。】

Installation

# Arch Linux
yay -S bat
# Fedora/CentOS
dnf install bat
# Debian/Ubuntu
apt install bat
# macOS/Linux Homebrew
brew install bat
# macOS MacPorts
port install bat
# Windows Scoop
scoop install bat
# Cargo
cargo install bat --locked

LSD and exa

Both LSD and exa are replacements for the ls command. They both look gorgeous with nice colors and icons and have features like headers, sorting, tree views, and so on. Exa is a bit faster than LSD for tree views and can show the Git status of files and folders. I prefer exa due to the Git support and faster tree views. I have set up my ls alias to use exa by default. Both can be configured to show custom columns and sorting behaviors.

【LSD和exa都是ls命令的替代品。它们都具有漂亮的颜色和图标,以及诸如标题、排序、树视图等功能。对于树视图,exa比LSD稍快一些,并且可以显示文件和文件夹的Git状态。由于支持Git和更快的树视图,我更喜欢exa。我已经将我的ls别名设置为默认使用exa。两者都可以配置为显示自定义列和排序行为。】

exa Installation

# Arch Linux
yay -S exa
# Fedora/CentOS
dnf install exa
# Debian/Ubuntu
apt install exa
# macOS Homebrew
brew install exa
# Cargo
cargo install exa

# Alias ls to exa
alias ls='exa --git --icons --color=always --group-directories-first'

LSD Installation

# Arch Linux
yay -S lsd
# Fedora/CentOS
dnf install lsd
# Debian/Ubuntu
dpkg -i lsd_0.23.1_amd64.deb # get .deb file from https://github.com/Peltoche/lsd/releases
# macOS Homebrew
brew install lsd
# macOS MacPorts
port install lsd
# Windows Scoop
scop install lsd
# Cargo
cargo install lsd

# Alias ls to lsd
alias ls='lsd --header --color=always --group-directories-first'

rip

rip is an improved version of the rm command. It is faster, safer, and user-friendly. rip sends deleted files to a temp location so they can be recovered using rip -u. I really like the simplicity and the revert feature, as I don’t have to worry about accidentally deleting something using rm. While rip can be aliased to replace rm, the creators advise not doing that as you might get used to it and do rm on other systems where you cannot revert the delete.

【rip是rm命令的改进版本。它更快、更安全、更用户友好。rip将已删除的文件发送到临时位置,因此可以使用rip -u恢复它们。我真的很喜欢它的简单性和还原功能,因为我不必担心使用rm意外删除某些内容。虽然rip可以别名为替换rm,但创建者建议不要这样做,因为您可能会习惯在其他系统上执行rm,而在那里您无法还原删除。】

Installation

# Arch Linux
yay -S rm-improved
# Fedora/CentOS/Debian/Ubuntu
# Install from binary or build locally using Cargo
# macOS Homebrew
brew install rm-improved
# Cargo
cargo install rm-improved

xcp

xcp is a partial clone of the cp command. It is faster and more user-friendly with progress bars, parallel copying, .gitignore support, and so on. I like its simplicity and developer experience, especially the progress bars. I have aliased cp to xcp so I can use it everywhere.

【xcp是cp命令的部分克隆。它更快、更用户友好,具有进度条、并行复制、.gitignore支持等功能。我喜欢它的简单性和开发者体验,特别是进度条。我已经将cp别名为xcp,以便我可以在任何地方使用它。】

Installation

# Arch Linux
yay -S xcp
# Fedora/CentOS/Debian/Ubuntu/macOS
# Install from binary or build locally using Cargo
# Cargo
cargo install xcp

# Alias cp to xcp
alias cp='xcp'

zoxide

zoxide is a smarter cd replacement. It remembers the directories you visit, and you can jump to them without providing a full path. You can provide partial paths or even a word from the path. When there are similar paths, zoxide offers an interactive selection using fzf. It is super fast and works with all major shells. I like how it works, and I have aliased cd to z so I can use it everywhere.

【zoxide是一个更智能的cd替换品。它会记住您访问过的目录,并且您可以在不提供完整路径的情况下跳转到它们。您可以提供部分路径,甚至可以是路径中的一个单词。当存在相似路径时,zoxide使用fzf提供交互式选择。它速度超快,适用于所有主要外壳。我喜欢它的工作方式,我已经将cd别名为z,这样我就可以在任何地方使用它。】

Installation

# Arch Linux
yay -S zoxide
# Fedora/CentOS
dnf install zoxide
# Debian/Ubuntu
apt install zoxide
# macOS/Linux Homebrew
brew install zoxide
# macOS MacPorts
port install zoxide
# Windows Scoop
scoop install zoxide
# Cargo
cargo install zoxide --locked

Once installed, you must add the following to your shell config file. For other shells, refer the docs

【一旦安装完成,您必须将以下内容添加到您的shell配置文件中。对于其他shell,请参阅文档。】

# bash (~/.bashrc)
eval "$(zoxide init bash)"
# zsh (~/.zshrc)
eval "$(zoxide init zsh)"
# fish (~/.config/fish/config.fish)
zoxide init fish | source

# Alias cd to z
alias cd='z'

dust

Dust is an alternative for the du command. It is fast and has a better UX with nice visualization for disk usage.

【Dust是du命令的替代品。它速度快,用户体验更好,对磁盘使用情况有很好的可视化效果。】

Installation

# Arch Linux
yay -S dust
# Fedora/CentOS
# Install binary from https://github.com/bootandy/dust/releases
# Debian/Ubuntu
deb-get install du-dust
# macOS Homebrew
brew install dust
# macOS MacPorts
port install dust
# Windows Scoop
scoop install dust
# Cargo
cargo install du-dust

ripgrep

ripgrep (rg) is a line-oriented search tool that recursively searches your current directory for a regex pattern. It is faster than grep and has many features like compressed files search, colorized output, smart case, file type filtering, multi-threading, and so on. It understands .gitignore files and skips hidden and ignored files. Here is a feature comparison with other similar tools, and yes, it is faster than all the other tools in the list.

【ripgrep(rg)是一个面向行的搜索工具,可以递归地搜索当前目录中的正则表达式模式。它比grep更快,并具有许多功能,如压缩文件搜索、彩色输出、智能大小写、文件类型过滤、多线程等。它理解.gitignore文件,并跳过隐藏和被忽略的文件。这是与其他类似工具的功能比较,是的,它比列表中的所有其他工具都要快。】

Installation

# Arch Linux
yay -S ripgrep
# Fedora/CentOS
dnf install ripgrep
# Debian/Ubuntu
apt-get install ripgrep
# macOS/Linux Homebrew
brew install ripgrep
# macOS MacPorts
port install ripgrep
# Windows Scoop
scoop install ripgrep
# Cargo
cargo install ripgrep

fd

fd is a simpler alternative to find. It is more intuitive to use and comes with sensible defaults. It is extremely fast due to parallel traversing and shows a modern colorized output and supports patterns and regex, parallel commands, smart case, understands .gitignore files, and so on. I have aliased find to fd as I could never remember what options to pass to get a basic find command working.

【fd是find命令的一个更简单的替代品。它更直观易用,并带有合理的默认值。由于采用并行遍历,它的速度非常快,并显示现代彩色输出,支持模式和正则表达式、并行命令、智能大小写,理解.gitignore文件等。我已经将find别名为fd,因为我永远记不住要让基本的find命令工作需要传递什么选项。】

Installation

# Arch Linux
yay -S fd
# Fedora/CentOS
dnf install fd-find
# Debian/Ubuntu
apt install fd-find
# macOS Homebrew
brew install fd
# macOS MacPorts
port install fd
# Windows Scoop
scoop install fd
# Cargo
cargo install fd-find

sd

sd is a find-and-replace CLI, and you can use it as a replacement for sed and awk. It is way more user-friendly and modern. It is also magnitudes faster than sed.

【sd是一个查找和替换的命令行工具,你可以用它来替代sed和awk。它更加用户友好和现代化。而且它的速度比sed快得多。】

Installation

# Arch Linux
yay -S sd
# Fedora/CentOS
dnf install sd
# Debian/Ubuntu
# Install binary from the release page
# macOS Homebrew
brew install sd
# Windows Scoop
choco install sd-cli
# Cargo
cargo install sd

procs

procs is a ps replacement. It provides colorized human-readable output, multi-column search, more information than ps, docker support, paging, watch mode, and tree view. It is a much more user-friendly and modern alternative to ps. You can filter by name and PID and use logical and/or operators to combine multiple filters. It also has a tree view which is very useful for seeing the process hierarchy. It can also show docker container names for the process running docker containers.

【procs是ps命令的替代品。它提供彩色的人类可读输出、多列搜索、比ps更多的信息、docker支持、分页、监视模式和树视图。它是ps的一个更友好和现代的替代品。你可以按名称和PID进行过滤,并使用逻辑与/或操作符组合多个过滤器。它还有一个树视图,对于查看进程层次结构非常有用。它还可以显示运行docker容器的进程的docker容器名称。】

Installation

# Arch Linux
yay -S procs
# Fedora/CentOS
dnf install procs
# Debian/Ubuntu
# Install binary from the release page
# macOS Homebrew
brew install procs
# macOS MacPorts
port install procs
# Windows Scoop
scoop install procs
# Cargo
cargo install procs

bottom

bottom is a top replacement with a nice terminal UI. It’s quite feature-rich and customizable.

【bottom是一个具有漂亮终端用户界面的top替代品。它功能丰富且可定制。】

Installation

# Arch Linux
yay -S bottom
# Fedora/CentOS
dnf copr enable atim/bottom -y
dnf install bottom
# Debian/Ubuntu
dpkg -i bottom_0.6.8_amd64.deb
# macOS Homebrew
brew install bottom
# macOS MacPorts
port install bottom
# Windows Scoop
scoop install bottom
# Cargo
cargo install bottom --locked

Topgrade

Topgrade is a fantastic utility if you prefer to keep your system up-to-date, like me. It detects most of the package managers on your system and triggers updates. It is configurable, so you can configure it to ignore certain package managers. On my system, it detected pacman, SDKMAN, Flatpak, snap, Homebrew, rustup, Linux firmware, Pip, and so on. Topgrade is cross-platform; you can use it on Windows, macOS, and Linux.

【如果你像我一样喜欢保持系统最新,那么Topgrade是一个了不起的实用程序。它可以检测系统上的大多数包管理器并触发更新。它是可配置的,因此你可以配置它来忽略某些包管理器。在我的系统上,它检测到了pacman、SDKMAN、Flatpak、snap、Homebrew、rustup、Linux固件、Pip等。Topgrade是跨平台的,你可以在Windows、macOS和Linux上使用它。】

Installation

# Arch Linux
yay -S topgrade
# Fedora/CentOS/Debian/Ubuntu/Windows
# Install binary from the release page
# macOS Homebrew
brew install topgrade
# macOS MacPorts
port install topgrade
# Cargo
cargo install topgrade --locked

Broot

Broot is a tree alternative with a better user experience, and you can use it to navigate a file structure. It’s fast and respects .gitignore. You can cd into a directory from the tree view, open sub-directories in a panel, and even preview files. It has excellent keyboard navigation as well. It has many more features.

【Broot是一款非常实用的文件导航工具,它提供了比传统树形命令更好的用户体验和功能。Broot的设计非常人性化,用户可以轻松地使用键盘或鼠标进行导航和操作。

Broot的主要功能包括文件结构导航、文件和目录预览、快速切换目录等。它支持.gitignore文件,可以自动忽略不需要显示的文件和目录。此外,Broot还提供了许多可定制的选项和快捷键,使得用户可以更加高效地进行文件操作。

Broot的用户界面非常直观和易于使用。它使用清晰的树形结构来显示文件和目录,用户可以轻松地浏览和定位所需的文件。Broot还支持在树形视图中直接打开子目录和预览文件内容,这大大提高了工作效率。】

Installation

# Arch Linux
yay -S broot
# Fedora/CentOS/Debian/Ubuntu/Windows
# Install binary from release page https://dystroy.org/broot/install/
# macOS Homebrew
brew install broot
# macOS MacPorts
port install broot
# Cargo
cargo install broot --locked

Tokei

Tokei is a nice utility to count lines and stats of code. It is very fast, accurate, and has a nice output. It supports over 150 languages and can output in JSON, YAML, CBOR, and human-readable tables.

【Tokei是一个很好的实用程序,用于计算代码的行数和统计信息。它非常快、准确,并且输出很好。它支持超过150种语言,并且可以输出JSON、YAML、CBOR和易于阅读的表格。】

Installation

# Arch Linux
yay -S tokei
# Fedora/CentOS
dnf install tokei
# Debian/Ubuntu
# Install binary from the release page
# macOS Homebrew
brew install tokei
# macOS MacPorts
port install tokei
# Windows Scoop
scoop install tokei
# Cargo
cargo install tokei

Other notable tools

  • kdash: A fast and simple dashboard for Kubernetes. Its created by me :)
  • Zellij: A feature rich modern terminal multiplexer with batteries included.
  • Nushell: A modern shell written in Rust. Looks quite promising.
  • xh: A HTTPie alternative with better performance.
  • monolith: Convert any webpage into a single HTML file with all assets inlined.
  • delta: A syntax-highlighting pager for git, diff, and grep output.
  • ripsecrets: Find secret keys in your code before committing them to git.
  • eva: A CLI REPL calculator.
  • You can find a list of other Rust CLI tools here

资料:

general-purpose

adj.

多用途的;多功能的

blazing

adj.

酷热的,炽热的;熊熊燃烧的;炫目的,鲜艳的;极其愤怒的,感情强烈的

a surge of

激增;高涨的

utilities

n.

实用;实用程序;效用;公用事业;公用程序;有用

utility的复数

intended

adj.

打算的;计划的;预定的;为…打算(或设计)的;意欲达到的

v.

打算;计划;想要;意指

intend的过去分词和过去式

n.

已订婚的人

counterparts

n.

职位(或作用)相当的人;对应的事物

counterpart的复数

supercharge

增压;增压器;机械增压;机械增压器;超级增压器

sensible

adj.

明智的,理智的;合理的;敏感的;可注意到的,大得能看得到的,明显的;知道的,意识到的,认识了的;切合实际的;(天平、温度计等)灵敏的;(服装等)实用的,不花哨的;实体的;有知觉的;感觉得到的,可觉察的;(衣服、鞋子)耐用的,朴素而实用的

n.

感觉得到的东西;敏感的人,善感的人

accelerated

v.

(使)加速;加快

adj.

加速的;加快的;跳级的

accelerate的过去分词和过去式

hence

adv.

因此,所以,由此;从现在,从此时起;<罕>从今以后,(用在一段时间后)以后;<古>从这地方,离此地;从今世,从此生

n.

另一世界;将来

int.

<古>去!滚开!

prompt

v.

鼓励,提示,提醒(某人说话);促使;导致;激起;给(演员)提词

adj.

迅速的;及时的;立即;准时的;敏捷的

n.

(给演员的)提词,提示;提示符

adv.

准时地

stuff

n.

(事物名称不详、无关紧要或所指事物明显时用)东西,物品,玩意儿;原料,材料;作品,作品(或演讲、乐曲等)的内容;基本特征,特质,根本;<口>能力,本事;物料,素材;行李,装备;(泛指)活儿,话,念头;家具;<英口><旧>无用的东西,废物;货色,财产;<口>毒品,麻醉剂(尤指海洛因);要素,基本的东西,特质,本质; <英>料子,毛料,呢绒;<美俚>赃物,走私货(尤指走私的威士忌酒);(发射出的)枪弹,炮弹;<美口><篮>灌篮,扣篮;<美口><棒>(投球手等使球旋转或呈曲线飞行等的)制球能力,制球

v.

把…塞进(或填进);使充满, 使充斥;填满,装满;<俚>处理掉, 丢掉;(使)吃撑,吃足,吃得过饱;给(皮革)加脂;<英俚> <忌>与(女人)性交;给……装馅;<美俚>诓骗, 作弄;<英口>(在比赛中)轻易击败(对手);在(蔬菜、鸡等)里填入(另外一种食物);<美>把伪票投入(票箱);制作(动物)标本

ligatures

n.

(用于紧缚的)带子,绳索,绷带;(用于止血等的)结扎丝,缚线

v.

绑扎;联结(ligature 的三单形式)

ligature的第三人称单数和复数

immediately

adv.

立即;马上;即刻;紧接;附近;接近;直接地;紧接地

conj.

一…就;即刻

precisely

adv.

准确地;(强调真实或明显)正是,确实;精确地;仔细地;恰好地;细心地;对,的确如此,一点也不错

combined

adj.

联合的;共同的;总共的;总计的

v.

(使)结合,组合,联合,混合;使融合(或并存);兼有;兼备;兼做;同时做(两件或以上的事);兼办

combine的过去分词和过去式

gorgeous

adj.

非常漂亮的;绚丽的;灿烂的;华丽的;美丽动人的;令人愉快的

temp

n.

临时工;临时雇员

vi.

打临时工;做临时工作;打零工

abbr.

温度

revert

v.

恢复,回复(到以前的状态、制度或行为);还原;回到,重提,重新考虑(某个话题);(财产、权力、金钱等)归还,归属

n.

归属;恢复原来信仰的人

accidentally

adv.

意外地;出其不意地;不知不觉地

partial

adj.

部分的,不完全的;<数>偏的;偏向一方的,偏袒的,不公平的;偏爱的,癖好的

n.

<音>分音(指泛音列诸音);<口>部分托牙,部分假牙

vt.

(在统计相关中)排除(一个或几个有关变量)的影响

oriented

v.

朝向;适应;使适应;面对;熟悉;确定方向;确定方位;认识方向

orient的过去分词和过去式

adj.

以…为方向的

recursively

递归地;递归;递归的;递归删除;回归

intuitive

adj.

直觉的;易懂的;有直觉力的;使用简便的;

extremely

adv.

极其;非常;极端

excellent

adj.

极好的;杰出的;非凡的;(用以表示愉快或赞同)好极了,妙极了

respects

v.

尊重;遵守;尊敬;不损害;仰慕;不违背;慎重对待;谨慎从事

n.

方面(respect 的复数);敬意;问候;关切

respect的第三人称单数

fantastic

adj.

好极了;极好的;了不起的;怪诞的;很大的;不切实际的;荒诞不经的;大得难以置信的;富于想象的

n.

古怪的人

logical

adj.

符合逻辑的;必然的;按照逻辑的;合乎情理的;合乎常理的

hierarchy

n.

等级制度(尤指社会或组织);统治集团;层次体系

magnitudes

n.

震级;巨大;星等;重大;重要性;星的亮度

magnitude的复数

原文:deepu.tech/rust-termin…