Rust 程式語言近年來在系統程式設計領域大放異彩,而其生態系統中湧現的命令列工具更是以速度快、記憶體安全、跨平台的特點征服了無數開發者。2026 年,Rust CLI 工具已經成熟到足以取代許多傳統工具。
本文將介紹 5 款在 2026 年最值得關注的 Rust CLI 工具,它們將徹底改變你的開發工作流程。
1. ast-grep:語法感知的程式碼搜尋神器
GitHub: https://github.com/ast-grep/ast-grep
官網: https://ast-grep.github.io/
如果你還在用 grep 搜尋程式碼,那你可能已經錯過了一個新時代。ast-grep(簡稱 sg)是一款基於抽象語法樹(AST)的程式碼搜尋和重寫工具,它能夠理解程式碼結構而非僅僅匹配文字。
為什麼選擇 ast-grep?
| 特性 | grep | ast-grep |
|---|---|---|
| 匹配方式 | 文字正規表示式 | AST 結構模式 |
| 理解語法 | ❌ | ✅ |
| 跨語言支援 | 有限 | 20+ 語言 |
| 程式碼重寫 | ❌ | ✅ |
| 速度 | 快 | 更快(Rust 最佳化) |
安裝方法
# macOS
brew install ast-grep
# Linux
curl -sSf https://ast-grep.github.io/install.sh | sh
# 使用 cargo
cargo install ast-grep
# Windows (winget)
winget install ast-grep
實用範例
搜尋所有 console.log 呼叫:
sg --pattern 'console.log($ARG)' --lang javascript
尋找未使用的變數:
sg --pattern 'let $VAR = $VALUE' --lang typescript
批次重寫程式碼(將 var 改為 let):
sg --pattern 'var $NAME = $INIT' \
--rewrite 'let $NAME = $INIT' \
--lang javascript \
-i
支援的語言
ast-grep 支援包括 JavaScript/TypeScript、Python、Rust、Go、Java、C/C++、Ruby、PHP 等 20 多種主流程式語言。完整的語言清單可在官方文件中檢視。
2. gitui:blazing fast 的終端 Git 客戶端
GitHub: https://github.com/gitui-org/gitui
對於習慣命令列的開發者來說,gitui 是一個完美的 Git 圖形介面替代品。它用 Rust 編寫,速度極快,資源佔用極低。
核心優勢
- ⚡ 極速啟動:比 lazygit 快 2 倍以上(基準測試:gitui 24s vs lazygit 57s)
- 🎨 現代化 UI:直觀的鍵盤驅動介面
- 🔧 完整 Git 功能:支援所有常用 Git 操作
- 📦 單二進位檔案:無需依賴,開箱即用
安裝方法
# macOS
brew install gitui
# Linux (snap)
snap install gitui
# 使用 cargo
cargo install gitui
# Arch Linux
pacman -S gitui
快速鍵速查
| 按鍵 | 功能 |
|---|---|
Tab |
切換面板 |
Enter |
確認操作 |
Esc |
返回/取消 |
c |
提交(Commit) |
p |
推送(Push) |
f |
拉取(Fetch) |
r |
變基(Rebase) |
m |
合併(Merge) |
d |
檢視差異(Diff) |
使用技巧
啟動後,gitui 會自動偵測目前目錄的 Git 儲存庫。介面分為四個主要區域:
- Unstaged Changes - 未暫存的變更
- Staged Changes - 已暫存的變更
- Commits - 提交歷史
- Branches - 分支管理
對於頻繁使用 Git 的開發者,gitui 可以顯著減少命令列輸入的負擔,同時保持終端工作流程的流暢性。
3. bottom (btm):跨平台系統監控工具
GitHub: https://github.com/ClementTsang/bottom
bottom 是一款用 Rust 編寫的跨平台系統監控工具,可以作為 top 或 htop 的現代替代品。
特色功能
- 🖥️ 視覺化圖表:CPU、記憶體、網路使用率的即時圖表
- 🔍 強大過濾:支援程序搜尋和過濾
- 🎨 高度可自訂:支援主題和版面配置
- 📊 磁碟和溫度監控:全面的系統資訊
安裝與使用
# macOS
brew install bottom
# Linux
curl -LO https://github.com/ClementTsang/bottom/releases/latest/download/bottom_x86_64-unknown-linux-gnu.tar.gz
tar -xzf bottom_x86_64-unknown-linux-gnu.tar.gz
# 使用 cargo
cargo install bottom
# 執行
btm
設定範例
建立設定檔 ~/.config/bottom/bottom.toml:
[flags]
hide_avg_cpu = true
dot_marker = true
temperature_type = "c"
[colors]
table_header_color = "blue"
all_cpu_color = "green"
avg_cpu_color = "red"
4. zoxide:智慧目錄跳轉工具
GitHub: https://github.com/ajeetdsouza/zoxide
zoxide 是一款用 Rust 編寫的智慧目錄跳轉工具,可以理解為現代版的 cd 命令。它會學習你的使用習慣,讓你用更少的按鍵到達目標目錄。
為什麼比 cd 更好?
# 傳統方式
cd ~/projects/dashen-tech/docs/dev-tools
# 使用 zoxide
z dev-tools # 自動匹配最常存取的路徑
安裝與設定
# 一鍵安裝(支援 bash、zsh、fish、PowerShell)
curl -sSf https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
# macOS
brew install zoxide
# 使用 cargo
cargo install zoxide
# 在 shell 設定檔中新增(~/.bashrc 或 ~/.zshrc)
eval "$(zoxide init bash)"
常用命令
| 命令 | 說明 |
|---|---|
z <關鍵詞> |
跳轉到匹配的目錄 |
zi <關鍵詞> |
互動式選擇目錄 |
z -l |
列出所有記錄的目錄 |
z -x <關鍵詞> |
在目標目錄執行命令 |
5. ripgrep (rg):極速程式碼搜尋工具
GitHub: https://github.com/BurntSushi/ripgrep
雖然 ripgrep 已經存在多年,但它在 2026 年仍然是 Rust CLI 工具中的標竿。它的搜尋速度比 grep 快數倍,並且預設忽略 .gitignore 中的檔案。
效能對比
在大型程式碼庫中的搜尋速度對比:
grep: 3.2 秒
ack: 1.8 秒
ag: 0.9 秒
ripgrep: 0.3 秒 ⚡
安裝方法
# macOS
brew install ripgrep
# Linux
sudo apt install ripgrep # Debian/Ubuntu
sudo dnf install ripgrep # Fedora
# 使用 cargo
cargo install ripgrep
實用技巧
搜尋包含模式的檔案:
rg "TODO|FIXME" --type rust
搜尋並顯示行號:
rg -n "error handling" src/
統計匹配次數:
rg --count "function" --type python
忽略特定目錄:
rg --ignore node_modules --ignore dist "pattern"
總結:為什麼選擇 Rust CLI 工具?
效能優勢
Rust 的零成本抽象和記憶體安全保證使得 CLI 工具在保持高效能的同時,避免了記憶體洩漏和段錯誤等常見問題。
跨平台支援
上述所有工具都支援 macOS、Linux 和 Windows,無需為不同平台尋找替代品。
活躍的社群
Rust 生態系統正在快速成長,新的 CLI 工具不斷湧現。關注以下資源獲取最新動態:
開始使用
建議從 ripgrep 和 zoxide 開始,它們的學習曲線最平緩,能立即提升日常工作效率。熟悉後,再逐步引入 ast-grep 和 gitui 等更專業的工具。
相關閱讀:
- 10 Modern Rust CLI Tools You Should Try in 2026
- The Complete Guide to Building Developer CLI Tools in 2026
- ast-grep 官方文件
如果你喜歡這篇文章,歡迎在評論區分享你最喜歡的 Rust CLI 工具!