⚡️ Znap! Fast, easy-to-use tools for Zsh dotfiles & plugins, plus git repos

在这之前一直使用的是https://ohmyz.sh/,使用一个大仓库集中管理了 所有常用的 Zsh 配置、插件、主题,而且管理的非常出色,也的确很好用,只是在安装仓库以外的插件时,不是很友好。此时如果需要的是一个通用的插件管理框架,znap 是一个不错的选择,将ohmyz视为插件仓库,搭配起来用,有一个非常不错的体验。

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout…

Install zsh-snap

将下面的内容添加到~/.zshrc,其中~/Repos可以修改为你想要任意的一个目录来保存插件或者 Git 仓库。

1
2
3
4
5
# Download Znap, if it's not there yet.
[[ -r ~/Repos/znap/znap.zsh ]] ||
    git clone --depth 1 -- \
        https://github.com/marlonrichert/zsh-snap.git ~/Repos/znap
source ~/Repos/znap/znap.zsh  # Start Znap

此时,只需要重启 Terminal 即可完成 snap 的安装。

Uninstall zsh-snap

卸载 snap 只需要将上面的配置从~/.zshrc 中移除,并删除~/Repos/即可。

下载插件

1
2
3
4
$ znap install sindresorhus/pure
$ znap install marlonrichert/zsh-autocomplete
$ znap install zsh-users/zsh-autosuggestions
$ znap install zsh-users/zsh-syntax-highlighting

使插件生效,需要在~/.zshrc 添加配置:

1
2
3
znap source marlonrichert/zsh-autocomplete
znap source zsh-users/zsh-autosuggestions
znap source zsh-users/zsh-syntax-highlighting

卸载

卸载一个或多个插件可以使用uninstall,如:

1
$ znap uninstall asdf-vm/asdf ohmyzsh/ohmyzsh

更新

更新 snap、安装的plugins 只需要运行:

1
$ znap pull

设置主题

znap install sindresorhus/pure 下载好主题后,在~/.zshrc 使之生效:

1
2
# `znap prompt` makes your prompt visible in just 15-40ms!
znap prompt sindresorhus/pure

也可以直接使用ohmyz中的主题,此时需要先下载ohmyz:

1
$ znap install ohmyzsh/ohmyzsh

然后在~/.zshrc配置加载必要ohmyz lib,再使用znap prompt指定主题:

1
2
znap source ohmyzsh/ohmyzsh lib/{git,theme-and-appearance}
znap prompt ohmyzsh/ohmyzsh robbyrussell

使用ohmyz仓库中的插件

1
znap source ohmyzsh/ohmyzsh lib/{git,theme-and-appearance} plugins/git plugins/zoxide plugins/macos

上面等同于在ohmyz中使用插件 plugins=(git macos zoxide)

配置实例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Download Znap, if it's not there yet.
[[ -r ~/Repos/znap/znap.zsh ]] ||
    git clone --depth 1 -- \
        https://github.com/marlonrichert/zsh-snap.git ~/Repos/znap
source ~/Repos/znap/znap.zsh  # Start Znap

# `znap prompt` makes your prompt visible in just 15-40ms!
znap prompt sindresorhus/pure

# plugins=(git macos zsh-autosuggestions zsh-syntax-highlighting zsh-autocomplete zoxide)
# `znap source` starts plugins.
znap source marlonrichert/zsh-autocomplete
znap source zsh-users/zsh-autosuggestions
znap source zsh-users/zsh-syntax-highlighting
# `znap prompt` also supports Oh-My-Zsh themes. Just make sure you load the
# required libs first:
znap source ohmyzsh/ohmyzsh lib/{git,theme-and-appearance} plugins/git plugins/zoxide plugins/macos
#znap prompt ohmyzsh/ohmyzsh robbyrussell 

参考

  1. the included .zshrc file.