2025 年每位开发者 & DevOps 工程师 🖥 都应使用的 24 个 Zsh 插件🔌

发布: (2025年12月5日 GMT+8 18:22)
6 min read
原文: Dev.to

Source: Dev.to

2024 Zsh 插件封面图🔌 每位开发者和 DevOps 工程师 🖥 在 2025 年都应使用

Introduction

如果你已经在使用带有 Oh My Zsh 的 Zsh,那么你已经走在了前列。但你是否充分利用了它的插件生态系统?让我来展示如何把你的终端变成生产力的强大引擎。

Prerequisites

在深入之前,请确保你已经具备:

  • 已安装 Zsh – 使用 zsh --version 检查(推荐 5.0 以上版本)
  • 已安装 Oh My Zsh – 若未安装,可使用以下命令安装:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • 已安装 Git – 用于克隆自定义插件
  • 基本的终端使用知识 – 你应该会使用 nanovim 或你喜欢的编辑器编辑文件

验证你的环境:

# 检查 Zsh 版本
zsh --version

# 检查 Oh My Zsh 是否已安装
ls ~/.oh-my-zsh

# 检查 Git
git --version

Why Plugins Matter

默认的 Oh My Zsh 安装只启用了 git 插件。虽然已经够好,但你仍然错过了智能自动补全、实用别名以及可以每周为你节省数小时的生产力快捷键。

The Setup

首先,安装两个社区插件,它们堪称改变游戏规则的利器:

  1. zsh-autosuggestions(类似 Fish 的建议)
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
  1. zsh-syntax-highlighting(实时命令校验)
git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

The Power Plugin List

打开 ~/.zshrc 文件,将 plugins=() 部分替换为下面的配置:

plugins=(
  # Version Control
  git

  # Cloud & Infrastructure
  docker
  docker-compose
  kubectl
  helm
  terraform
  aws
  gcloud
  azure
  ansible

  # Programming Languages & Tools
  python
  pip
  node
  npm
  yarn
  golang
  rust

  # Productivity Boosters
  sudo              # Press ESC twice to add sudo to previous command
  extract           # Universal archive extractor (works with .tar, .zip, .gz, etc.)
  z                 # Jump to frequently used directories
  history           # Enhanced history commands
  command-not-found # Suggests package to install for missing commands
  vscode            # VS Code aliases and shortcuts

  # Community Plugins (must be last)
  zsh-autosuggestions
  zsh-syntax-highlighting
)

What Each Plugin Does

Cloud & Infrastructure Plugins

  • docker & docker-compose – 为容器、镜像以及 compose 命令提供自动补全
  • kubectl – Kubernetes 命令补全及实用别名(k 代表 kubectlkgp 代表 kubectl get pods
  • helm – Helm Chart 管理补全
  • terraform – Terraform 命令补全
  • aws / gcloud / azure – 各云提供商 CLI 的补全

Language Plugins

  • python / pip – Python 环境和包管理快捷方式
  • node / npm / yarn – JavaScript 生态系统补全
  • golang / rust – 针对语言的工具支持

Productivity Plugins

  • sudo – 双击 ESC 为上一次命令加上 sudo 前缀
  • extract – 使用 extract <file> 解压任意归档,无需记忆 tar 参数
  • z – 使用一段时间后,输入 z project 即可跳转到 /home/user/dev/project
  • command-not-found – 在缺少命令时提示应安装的包(Ubuntu/Debian)

Community Plugins

  • zsh-autosuggestions – 根据历史记录实时显示建议(按 → 接受)
  • zsh-syntax-highlighting – 有效命令显示为绿色,无效命令显示为红色——在执行前捕获拼写错误

Activate Your Configuration

更新 .zshrc 后,重新加载:

source ~/.zshrc

Real-World Examples

Before

$ kubctl get pods  # Typo turns red immediately
$ # Realize mistake, fix it
$ kubectl get pods

After with plugins

  • 拼写错误会立即以红色高亮。
  • 开始输入 kub... 时,自动建议会显示历史中的 kubectl get pods
  • 按 → 接受。

或者使用别名 kk get pods

Directory Navigation

# Old way
$ cd ~/projects/work/important-service/

# With 'z' plugin (after visiting once)
$ z important
# Instantly jumps to ~/projects/work/important-service/

Archive Extraction

# Old way
$ tar -xzvf file.tar.gz
$ unzip archive.zip
$ tar -xjf file.tar.bz2

# New way with 'extract' plugin
$ extract file.tar.gz
$ extract archive.zip
$ extract file.tar.bz2
# All work the same way!

Performance Considerations

插件太多会导致 shell 启动变慢。如果你注意到卡顿:

  • 只启用真正使用的插件
  • 移除不涉及的语言插件
  • 使用 time zsh -i -c exit 测量启动时间

Bonus: Useful Aliases from These Plugins

激活后,你将拥有数十个实用别名:

Docker

  • dpsdocker ps
  • dpadocker ps -a
  • dcedocker-compose exec

Kubectl

  • kkubectl
  • kgpkubectl get pods
  • kgdkubectl get deployments
  • kafkubectl apply -f

Git

  • gstgit status
  • gcgit commit
  • gpgit push
  • gcogit checkout

在终端运行 alias 可查看所有可用别名。

Next Steps

  • 探索主题 – 试试 agnosterpowerlevel10k,获得美观的提示符
  • 自定义别名 – 在 ~/.zshrc~/.oh-my-zsh/custom/aliases.zsh 中添加自己的别名
  • 发现更多插件 – 运行 ls ~/.oh-my-zsh/plugins/ 查看 350+ 可用插件

Conclusion

配置良好的终端是开发者的最佳伙伴。这些插件将 Zsh 从普通的 shell 变成智能助理,能够在你输入时自动补全、提供建议并进行校验。初始配置大约只需 5 分钟,但通过提升效率和减少上下文切换,你每周能节省数小时。

你使用哪些插件?在评论区分享你的最爱吧!

Back to Blog

相关文章

阅读更多 »