🔀 Standard Syntax
Introduction
Zi 为结构化语句或表达式提供了两种语法类型:
- Standard syntax
- The "For" syntax
用户可以自行决定使用哪种语法,但强烈建议熟悉这两种语法。 在本例中,我们将使用一个空存储库 z-shell/0 来练习标准语法的基础知识。
- 在终端中执行下列命令:
zi load z-shell/0
成功安装 Zsh 插件,该插件通常包含 Zsh 插件标准 中描述的所有设置说明。
代码片段是一个带有可重用源代码一部分的单一文件。 机器代码或文本,需要文件的完整 路径或 URL。
- 在终端中执行下列命令:
zi snippet https://raw.githubusercontent.com/z-shell/zi-src/main/lib/zsh/snippets/welcome.zsh
Success! 但并不总是一切都那么容易和简单,有时我们也希望某些事情在特定的时间或条件下发生。 This can be achieved using ice-modifiers.
顶部行包含 ice - modifiers ,而底部行是插件。
- 在终端中执行下列命令:
zi ice id-as'zsh/plugin' atinit'print "Hello World!"'
zi load z-shell/0
这将在 插件 IDzsh/plugin,而不是 z-shell/0 下注册插件。 这将按预期工作,例如, zi update zsh/plugin, zi remove zsh/plugin,等等。 The "Hello World!" printed before loading the plugin
请使用更多的 ice - modifiers 重新安装。
- 在终端中执行下列命令:
zi ice id-as'final/countdown' \
atinit'+zi-message "{bapo}Cloned!"' \
atclone'+zi-message "{quos}Boom!"' \
atload'+zi-message "{apo}Loaded!"' countdown
zi load z-shell/0
Order of execution
The order of execution of related ice-modifiers is as follows:
atinit'' →
atpull'!' →
make'!!' →
mv'' →
cp'' →
make'!' →
atclone'' / atpull'' →
make'!' →
[ plugin script loading ] →
src'' →
multisrc'' →
atload''
A few remarks
- The syntax automatically detects if the object is a snippet or a plugin, by checking if the object is an URL, i.e.: if it starts with
http*://orOMZ::, etc. - To load a local-file snippet (which will be treated as a local-directory plugin by default) use the
is-snippetice, - To load a plugin in
lightmode use thelight-modeice. - If the plugin name collides with an ice name, precede the plugin name with
@, e.g.:@sharkdp/fd(collides with theshice, ZI will take the plugin name assh"arkdp/fd"), see the next section for an example.
Syntax alternatives
Zi supports alternatives such as the equal (=) syntax:
zi ice id-as=equal atload="print Hello World"
zi load z-shell/0
The colon (:) syntax:
zi ice id-as:colon atload:"print Hello World"
zi load z-shell/0