Zsh + Antigen + Oh my Zsh = 美观、强大、健壮的 Shell Zsh Antigen Oh my Zsh

2025-06-07

Zsh + Antigen + Oh my Zsh = 美观、强大、健壮的 Shell

Zsh

抗原

哦我的Zsh

我已经用默认的普通 Shell 工作了很长时间,直到我意识到自己再也无法每天面对那个“丑陋无趣的家伙”了。作为一名开发者,我使用 Shell 的时间比和任何亲戚(包括我的妈妈、女朋友或室友)相处的时间都多。因此,我需要一个更好的伴侣:

  • 它应该很漂亮,这样我才能每天舒服地看它几个小时。
  • 它应该功能强大,智能,这样才能帮助我更快、更方便地做事。
  • 它应该是稳定的,否则我将无法工作,直到它被修复。
  • 它应该是可配置和可扩展的,以便我可以轻松地添加或删除一些功能。

👉🏻 经过一段时间的研究和试验可用的工具后,我发现 Zsh + Antigen + Oh my Zsh 确实符合我的期望,并且是迄今为止最好的解决方案。

演示


Zsh

Z shellZsh 是一个扩展的 Unix shell,具有许多改进,包括 [Bash]( https://en.wikipedia.org/wiki/Bash_(Unix_shell))kshtcsh的一些功能。

Zsh 本身并不美观也不智能,但它具有可扩展性,可以应用社区开发的插件,使其变得美观而强大。

Zsh 非常流行,它被发布到几乎所有 Unix 发行版(Ubuntu、Centos、macOS 等)的软件包存储库中,以便您可以使用软件包管理器轻松安装 Zsh:

# Ubuntu
sudo apt-get install -y zsh

# CentOS
sudo yum install -y zsh

# macOS (since macOS Catalina, Zsh has been installed with the OS)
brew install zsh
Enter fullscreen mode Exit fullscreen mode

抗原

正如我们所说,Zsh 支持可插拔性,以便用户可以安装插件并扩展其功能。然而,Zsh 本身并没有提供良好的插件管理机制,包括获取、安装、更新、删除插件等。

幸运的是,Antigen很好地承担了这一责任。大多数 Zsh 插件都以 git 仓库的形式发布。Antigen 允许我们简单地指定远程仓库的路径,然后它会在第一次运行时自动获取并安装。Antigen 还提供了方便更新和删除插件的命令。

安装

首先,下载 Antigen,只需运行:

curl -L git.io/antigen > antigen.zsh
Enter fullscreen mode Exit fullscreen mode

然后,将以下几行粘贴到您的文件中~/.zshrc(如果您没有该文件,请创建一个):

# Load Antigen
source "/path-to-your/antigen.zsh"

# Load Antigen configurations
antigen init ~/.antigenrc
Enter fullscreen mode Exit fullscreen mode

配置

~/.antigenrc将是您的 Antigen 配置文件,其中列出了插件和主题。

以下是我的~/.antigenrc

# Load oh-my-zsh library
antigen use oh-my-zsh

# Load bundles from the default repo (oh-my-zsh)
antigen bundle git
antigen bundle command-not-found
antigen bundle docker

# Load bundles from external repos
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting

# Select theme
antigen theme denysdovhan/spaceship-prompt

# Tell Antigen that you're done
antigen apply
Enter fullscreen mode Exit fullscreen mode

现在先跳过这一行antigen use oh-my-zsh,我们将在下一节讨论这个问题。

要指定要应用的插件:

antigen bundle remote-repo/url
Enter fullscreen mode Exit fullscreen mode

例如zsh-users/zsh-completionszsh-users/zsh-autosuggestions实际上指向github.com/zsh-users/zsh-completionsgithub.com/zsh-users/zsh-autosuggestions。Github 会自动推断,如果存储库托管在不同的域下,只需指定域即可。

要应用主题,请使用antigen theme remote-repo/url

最后,您需要antigen apply冻结线路并应用所有先前的配置。

我刚刚使用了几个插件,你可以在这里找到其他很棒的插件。


哦我的Zsh

Oh my Zsh是一个 Zsh 配置框架,它嵌入了一堆插件和主题,以便您可以轻松地打开和关闭它们。

您可以通过将 添加antigen use oh-my-zsh到 中来轻松地将 Oh my Zsh 与 Antigen 一起使用~/.antigenrc

然后,打开插件或使用 Oh my Zsh 的主题:

# Turn on an Oh my Zsh plugin
antigen bundle plugin-name
antigen bundle git
antigen bundle command-not-found
antigen bundle docker

# Apply an Oh my Zsh theme
antigen theme theme-name
antigen theme robbyrussell
Enter fullscreen mode Exit fullscreen mode

请参阅以下链接以获取 Oh my Zsh插件主题的完整列表


希望你也喜欢 Zsh!如果你喜欢这篇文章,欢迎在 Twitter 上留言,一起交流有趣的编程想法。😉

文章来源:https://dev.to/phuctm97/zsh-antigen-oh-my-zsh-a-beautiful-powerful-and-robust-shell-5da4
PREV
我如何构建我的 React 项目
NEXT
Vue <3 GraphQL