☑️ 一般概述
此概览包括以下内容:
加载插件和片段
zi load z-shell/H-S-MW
zi light zsh-users/zsh-syntax-highlighting
上面的命令显示了两种加载基本插件的方式。 If you want to source local or remote files (using a direct URL), you can do so with a snippet
.
zi snippet <URL>
Such lines should be added to .zshrc
. Snippets are cached locally, use the -f
option to download a fresh version of a snippet, or zi update {URL}
. Use zi update --all
to update all snippets and plugins.
Using load
causes reporting to be enabled – you can track what the plugin does, view the information with zi report {plugin-name}
, and then also unload the plugin with zi unload {plugin-name}
.
Using light
is a faster loading without tracking and reporting about the plugin but also withdrawing the ability to unload it.
Using load
or light
:
zi load <repo/plugin> # Load with reporting/investigating.
zi light <repo/plugin> # Load without reporting/investigating.
带着跟踪报告加载 history-search-multi-word 插件:
zi load z-shell/H-S-MW
不带跟踪报告加载两个普通插件:
zi light zsh-users/zsh-autosuggestions
zi light z-shell/F-Sy-H
片段:
zi snippet https://gist.githubusercontent.com/hightemp/5071909/raw/
In turbo mode loading, the slowdown by plugin tracking is done in the background and does not affect the user experience, i.e., loading with zi light
and zi load
has the same effect.
Oh-My-Zsh, Prezto
To load Oh-My-Zsh and Prezto plugins, use the snippet
feature. Snippets are single files downloaded by curl
, wget
, etc., automatic detection of the download tool is being performed, directly from the URL:
zi snippet 'https://github.com/robbyrussell/oh-my-zsh/raw/master/plugins/git/git.plugin.zsh'
zi snippet 'https://github.com/sorin-ionescu/prezto/blob/master/modules/helper/init.zsh'
Also, for Oh-My-Zsh and Prezto, you can use OMZ::
and PZT::
shorthands:
zi snippet OMZ::plugins/git/git.plugin.zsh
zi snippet PZT::modules/helper/init.zsh
此外,GitHub 支持通过 Subversion 协议加载片段。 This allows loading snippets that are multi-file (for example, a Prezto module can consist of two or more files, e.g. init.zsh
and alias.zsh
).
Default files that will be sourced are: *.plugin.zsh
, init.zsh
, *.zsh-theme
:
指向目录的URL:
zi ice svn
zi snippet PZT::modules/docker
Snippet 和性能
Using curl
, wget
, etc. along with Subversion allows us to almost completely avoid code dedicated to Oh-My-Zsh and Prezto, and also to other frameworks. 它提供了更好的性能,因为它对内存的占用很低,加载时间更短。
Ice 修饰符
The command zi ice
provides ice modifiers for the single Zi command, i.e., zi ice <some-ice-modifier>; zi load some/plugin
, after loading some/plugin the ice-modifier has to be set again.
“冰”是一种添加物,例如添加到饮料或咖啡中 —— 在 Zi 里,冰修饰符将是下一条 Zi 命令的添加物。 “冰”也是会融化的东西,所以它不会留存很久 —— 在 Zi 里,这意味着它的效果只能作用于一条命令。
Using one other ice modifier "pick" users can explicitly select the file to source:
zi ice svn pick"init.zsh"
zi snippet PZT::modules/git
The content of the ice-modifier is simply put into "…"
, '…'
, $'…'
. No need for ":"
after the ice-modifier name (although it's allowed: as the equal sign =
, e.g. pick="init.zsh"
or pick=init.zsh
).
This way editors like vim
and emacs
and also zsh-users/zsh-syntax-highlighting
and z-shell/F-Sy-H
will highlight the contents of ice-modifiers.
关于 as"program"
A plugin might not be a file for sourcing, but a command to be added to $PATH
. To obtain this effect, use ice-modifier as
with value program
(or an alias value command
).
zi ice as"program" cp"httpstat.sh -> httpstat" pick"httpstat"
zi light b4b4r07/httpstat
The above command will add plugin directory to $PATH
, copy file httpstat.sh
into httpstat
and add execution rights (+x
) to the file selected with pick
, i.e. to httpstat
. Another ice-mod exists, mv
, which works like cp
but moves a file instead of copying it. mv
is run before cp
.
The cp
and mv
ices (and also some other ones, like atclone
) are being run when the plugin or snippet is being installed. To test them again first delete the plugin or snippet (example: zi delete PZT::modules/osx
).
Ice 修饰符: atpull'…'
Copying file is safe for doing later updates – original files of the repository are unmodified and Git
will report no conflicts. However, mv
also can be used, if a proper atpull
, an ice-modifier ran at update of the plugin:
zi ice as"program" mv"httpstat.sh -> httpstat" \
pick"httpstat" atpull'!git reset --hard'
zi light b4b4r07/httpstat
If atpull
starts with an exclamation mark, then it will be run before git pull
, and before mv
. Nevertheless, atpull
, mv
, and cp
are run only if new commits are to be fetched.
So in summary, when the user runs zi update b4b4r07/httpstat
to update this plugin, and there are new commits, what happens first is that git reset --hard
is run – and it restores original httpstat.sh
, then git pull
is ran and it downloads new commits (doing fast-forward), then mv
is running again so that the command is httpstat
not httpstat.sh
.
This way the mv
ice can be used to induce permanent changes into the plugin's contents without blocking the ability to update it with git
or with subversion
in the case of snippets.
For exclamation marks to not be expanded by Zsh an interactive session, use '…'
not "…"
to enclose contents of atpull
ice-modifier.
Ice 修饰符: subscribe'…'
Ice修饰符延迟加载加载一个插件,同时检查给定文件的修改时间。当给定文件发生变化时,它就会触发插件或片段的加载。
Copy and paste the example below to the terminal or add it to the .zshrc
file and reload the shell with exec zsh
.
zi ice subscribe'{~/files-*,/tmp/files-*}' id-as'z-sub' lucid \
atload'+zi-message "{profile}I have been loaded{nl}\
{auto}\`Zi Rocks ♥\`"' notify"Yes that is cool ♥ "
zi load z-shell/0
按照上面订阅的内容更新文件,测试 Ice 修饰符:
touch ~/files-1
该插件或片段将随着文件的更新而被 source 。
片段 as'…' program
Commands can also be added to $PATH
using snippets:
zi ice mv"httpstat.sh -> httpstat" \
pick"httpstat" as"program"
zi snippet https://github.com/b4b4r07/httpstat/blob/master/httpstat.sh
Snippets also support atpull
, e.g. atpull'!svn revert'
. There’s also an atinit
ice-modifier, executed before each loading of plugin or snippet.
片段 as'…' completion
By using the as'…'
ice modifier with the value completion
you can point the snippet
subcommand directly to a completion file:
zi ice as"completion"
zi snippet https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker
补全管理
Zi允许在每个插件中禁用和启用每个补全。 尝试安装一个提供补全的热门插件:
zi ice blockf
zi light zsh-users/zsh-completions
The first command, the blockf
ice, will block the traditional method of adding completions. Zi uses this method, based on symlinks instead of adding several directories to $fpath
. Zi will automatically install completions of a newly downloaded plugin.
要卸载或安装补全:
卸载:
zi cuninstall zsh-users/zsh-completions
安装:
zi creinstall zsh-users/zsh-completions