![](/style/images/good.png)
![](/style/images/bad.png)
GitHub - zdharma-continuum/zinit: Zinit is a flexible and fast Zshell plugin man...
source link: https://github.com/zdharma-continuum/zinit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
zinit
Note: Sebastian Gniazdowski, the original
zinit
dev, deletedzdharma
randomly. This is a reliable fork / place for the continuation of the project.
Table of Contents generated with DocToc
Here are the new features and updates added to Zinit in the last 90 days.
To see the full history check the changelog.
Zinit
Zinit is a flexible and fast Zshell plugin manager that will allow you to install everything from GitHub and other sites. Its characteristics are:
-
Zinit is currently the only plugin manager out there that provides Turbo mode which yields 50-80% faster Zsh startup (i.e.: the shell will start up to 5 times faster!). Check out a speed comparison with other popular plugin managers here.
-
The plugin manager gives reports from plugin loadings describing what aliases, functions, bindkeys, Zle widgets, zstyles, completions, variables,
PATH
andFPATH
elements a plugin has set up. This allows to quickly familiarize oneself with a new plugin and provides rich and easy to digest information which might be helpful on various occasions. -
Supported is unloading of plugin and ability to list, (un)install and selectively disable, enable plugin's completions.
-
The plugin manager supports loading Oh My Zsh and Prezto plugins and libraries, however the implementation isn't framework specific and doesn't bloat the plugin manager with such code (more on this topic can be found on the Wiki, in the Introduction).
-
The system does not use
$FPATH
, loading multiple plugins doesn't clutter$FPATH
with the same number of entries (e.g.10
,15
or more). Code is immune toKSH_ARRAYS
and other options typically causing compatibility problems. -
Zinit supports special, dedicated packages that offload the user from providing long and complex commands. See the Zsh-Packages organization for a growing, complete list of Zinit packages and the Wiki page for an article about the feature.
-
Also, specialized Zinit extensions — called annexes — allow to extend the plugin manager with new commands, URL-preprocessors (used by e.g.: z-a-as-monitor annex), post-install and post-update hooks and much more. See the zdharma-continuum organization for a growing, complete list of available Zinit extensions and refer to the Wiki article for an introduction on creating your own annex.
Zinit Wiki
The information in this README is complemented by the Zinit Wiki. The README is an introductory overview of Zinit while the Wiki gives a complete information with examples. Make sure to read it to get the most out of Zinit.
Quick Start
Install
Automatic Installation (Recommended)
The easiest way to install Zinit is to execute:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma-continuum/zinit/master/doc/install.sh)"
This will install Zinit in ~/.zinit/bin
.
.zshrc
will be updated with three lines of code that will be added to the bottom.
The lines will be sourcing zinit.zsh
and setting up completion for command zinit
.
After installing and reloading the shell compile Zinit with zinit self-update
.
Manual Installation
To manually install Zinit clone the repo to e.g. ~/.zinit/bin
:
mkdir ~/.zinit git clone https://github.com/zdharma-continuum/zinit.git ~/.zinit/bin
and source it from .zshrc
(above compinit):
source ~/.zinit/bin/zinit.zsh
If you place the source
below compinit
, then add those two lines after the source
:
autoload -Uz _zinit (( ${+_comps} )) && _comps[zinit]=_zinit
Various paths can be customized, see section Customizing Paths.
After installing and reloading the shell compile Zinit with zinit self-update
.
Usage
Introduction
Click here to read the introduction to Zinit. It explains basic usage and some of the more unique features of Zinit such as the Turbo mode. If you're new to Zinit we highly recommend you read it at least once.
Plugins and snippets
Plugins can be loaded using load
or light
.
zinit load <repo/plugin> # Load with reporting/investigating. zinit light <repo/plugin> # Load without reporting/investigating.
If you want to source local or remote files (using direct URL), you can do so with snippet
.
zinit snippet <URL>
Such lines should be added to .zshrc
. Snippets are cached locally, use -f
option to download
a fresh version of a snippet, or zinit update {URL}
. Can also use zinit update --all
to
update all snippets (and plugins).
Example
# Plugin history-search-multi-word loaded with investigating. zinit load zdharma-continuum/history-search-multi-word # Two regular plugins loaded without investigating. zinit light zsh-users/zsh-autosuggestions zinit light zdharma-continuum/fast-syntax-highlighting # Snippet zinit snippet https://gist.githubusercontent.com/hightemp/5071909/raw/
Prompt(Theme) Example
This is powerlevel10k, pure, starship sample:
# Load powerlevel10k theme zinit ice depth"1" # git clone depth zinit light romkatv/powerlevel10k # Load pure theme zinit ice pick"async.zsh" src"pure.zsh" # with zsh-async library that's bundled with it. zinit light sindresorhus/pure # Load starship theme zinit ice as"command" from"gh-r" \ # `starship` binary as command, from github release atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \ # starship setup at clone(create init.zsh, completion) atpull"%atclone" src"init.zsh" # pull behavior same as clone, source init.zsh zinit light starship/starship
Upgrade Zinit and plugins
Zinit can be updated to self-update
and plugins to update
.
# Self update zinit self-update # Plugin update zinit update # Plugin parallel update zinit update --parallel # Increase the number of jobs in a concurrent-set to 40 zinit update --parallel 40
Turbo and lucid
Turbo and lucid are the most used options.
Turbo Mode Turbo mode is the key to performance. It can be loaded asynchronously, which makes a huge difference when the amount of plugins increases.
Lucid
F&A: What is ice
?
ice
is zinit's option command. The option melts like ice and is used only once.
(more: Ice Modifiers)
Migration
Migration from Oh-My-ZSHMigration from PreztoMigration from ZgenMigration from Zplug
More Examples
After installing Zinit you can start adding some actions (load some plugins) to ~/.zshrc
, at bottom. Some examples:
# Load the pure theme, with zsh-async library that's bundled with it. zinit ice pick"async.zsh" src"pure.zsh" zinit light sindresorhus/pure # A glance at the new for-syntax – load all of the above # plugins with a single command. For more information see: # https://zdharma-continuum.github.io/zinit/wiki/For-Syntax/ zinit for \ light-mode zsh-users/zsh-autosuggestions \ light-mode zdharma-continuum/fast-syntax-highlighting \ zdharma-continuum/history-search-multi-word \ light-mode pick"async.zsh" src"pure.zsh" \ sindresorhus/pure # Binary release in archive, from GitHub-releases page. # After automatic unpacking it provides program "fzf". zinit ice from"gh-r" as"program" zinit light junegunn/fzf # One other binary release, it needs renaming from `docker-compose-Linux-x86_64`. # This is done by ice-mod `mv'{from} -> {to}'. There are multiple packages per # single version, for OS X, Linux and Windows – so ice-mod `bpick' is used to # select Linux package – in this case this is actually not needed, Zinit will # grep operating system name and architecture automatically when there's no `bpick'. zinit ice from"gh-r" as"program" mv"docker* -> docker-compose" bpick"*linux*" zinit load docker/compose # Vim repository on GitHub – a typical source code that needs compilation – Zinit # can manage it for you if you like, run `./configure` and other `make`, etc. stuff. # Ice-mod `pick` selects a binary program to add to $PATH. You could also install the # package under the path $ZPFX, see: http://zdharma-continuum.github.io/zinit/wiki/Compiling-programs zinit ice as"program" atclone"rm -f src/auto/config.cache; ./configure" \ atpull"%atclone" make pick"src/vim" zinit light vim/vim # Scripts that are built at install (there's single default make target, "install", # and it constructs scripts by `cat'ing a few files). The make'' ice could also be: # `make"install PREFIX=$ZPFX"`, if "install" wouldn't be the only, default target. zinit ice as"program" pick"$ZPFX/bin/git-*" make"PREFIX=$ZPFX" zinit light tj/git-extras # Handle completions without loading any plugin, see "clist" command. # This one is to be ran just once, in interactive session. zinit creinstall %HOME/my_completions
# For GNU ls (the binaries can be gls, gdircolors, e.g. on OS X when installing the # coreutils package from Homebrew; you can also use https://github.com/ogham/exa) zinit ice atclone"dircolors -b LS_COLORS > c.zsh" atpull'%atclone' pick"c.zsh" nocompile'!' zinit light trapd00r/LS_COLORS
You can see an extended explanation of LS_COLORS in the Wiki.
# make'!...' -> run make before atclone & atpull zinit ice as"program" make'!' atclone'./direnv hook zsh > zhook.zsh' atpull'%atclone' src"zhook.zsh" zinit light direnv/direnv
You can see an extended explanation of direnv in the Wiki.
If you're interested in more examples then check out the zinit-configs
repository where users have uploaded their
~/.zshrc
and Zinit configurations. Feel free to
submit
your ~/.zshrc
there if it contains Zinit commands.
You can also check out the Gallery of Zinit Invocations for some additional examples.
Also, two articles on the Wiki present an example setup here and here.
How to Use
Ice Modifiers
Following ice
modifiers are to be
passed to zinit ice ...
to
obtain described effects. The word ice
means something that's added (like ice to a
drink) – and in Zinit it means adding modifier to a next zinit
command, and also
something that's temporary because it melts – and this means that the modification will
last only for a single next zinit
command.
Some Ice-modifiers are highlighted and clicking on them will take you to the appropriate Wiki page for an extended explanation.
You may safely assume a given ice works with both plugins and snippets unless explicitly stated otherwise.
Cloning Options
Modifier Descriptionproto
git
,ftp
,ftps
,ssh
, rsync
, etc. Default is https
. Does not work with snippets. from
from"github"
(default), ..."github-rel"
, ..."gitlab"
, ..."bitbucket"
, ..."notabug"
(short names: gh
, gh-r
, gl
, bb
, nb
). Can also be a full domain name (e.g. for GitHub enterprise). Does not work with snippets.ver
from"gh-r"
(i.e. downloading a binary release, e.g. for use with as"program"
) – selects which version to download. Default is latest, can also be explicitly ver"latest"
. Works also with regular plugins, checkouts e.g. ver"abranch"
, i.e. a specific version. Does not work with snippets.bpick
zini ice from"gh-r" as"program" bpick"*Darwin*"; zini load docker/compose
. Does not work with snippets. depth
--depth
to git
, i.e. limit how much of history to download. Does not work with snippets.cloneopts
cloneopts
to git clone
. Defaults to --recursive
. I.e.: change cloning options. Pass empty ice to disable recursive cloning. Does not work with snippets. pullopts
pullopts
to git pull
used when updating plugins. Does not work with snippets. svn
SVN
protocol, this allows to clone subdirectories as snippets, e.g. zinit ice svn; zinit snippet OMZP::git
. Other ice pick
can be used to select file to source (default are: *.plugin.zsh
, init.zsh
, *.zsh-theme
). Does not work with plugins.Selection of Files (To Source, …)
Modifier Descriptionpick
snippet --command
or the ice as"program"
); it is a pattern, alphabetically first matched file is being chosen; e.g. zinit ice pick"*.plugin.zsh"; zinit load …
.src
as"program"
). It is not a pattern but a plain file name.multisrc
multisrc'misc.zsh grep.zsh'
) and also using brace-expansion syntax (e.g. multisrc'{misc,grep}.zsh'
). Supports patterns.Conditional Loading
Modifier Descriptionwait
wait'1'
, loading is done 1
second after prompt. For wait'[[ ... ]]'
, wait'(( ... ))'
, loading is done when given condition is meet. For wait'!...'
, prompt is reset after load. Zsh can start 80% (i.e.: 5x) faster thanks to postponed loading. Fact: when wait
is used without value, it works as wait'0'
.load
unload
below). E.g.: load'[[ $PWD = */github* ]]'
.unload
unload'[[ $PWD != */github* ]]'
.cloneonly
if
zinit ice if'[[ -n "$commands[otool]" ]]'; zinit load ...
.has
zinit ice has'git' ...
subscribe
/ on-update-of
subscribe'{~/files-*,/tmp/files-*}'
trigger-load
!
) to automatically forward the call afterwards, to a command of the same name as the function. Can obtain multiple functions to create – sparate with ;
.Plugin Output
Modifier Descriptionsilent
stderr
& stdout
. Also skip Loaded ...
message under prompt for wait
, etc. loaded plugins, and completion-installation messages.lucid
Loaded ...
message under prompt for wait
, etc. loaded plugins (a subset of silent
).notify
!
it will then always output the given message. Hint: if the message is empty, then it will just notify about problems.Completions
Modifier Descriptionblockf
fpath
. Useful when a plugin wants to provide completions in traditional way. Zinit can manage completions and plugin can be blocked from exposing them.nocompletions
zinit creinstall {plugin-spec}
.Command Execution After Cloning, Updating or Loading
Modifier Descriptionmv
mv "fzf-* -> fzf"
. It uses ->
as separator for old and new file names. Works also with snippets.cp
cp "docker-c* -> dcompose"
. Ran after mv
.atclone
zinit ice atclone"echo Cloned"
. Ran also after downloading snippet.atpull
mv
& cp
ices and before git pull
or svn update
. Otherwise it is ran after them. Can be atpull'%atclone'
, to repeat atclone
Ice-mod.atinit
atload
!
, it will then be investigated (if using load
, not light
).run-atpull
nocd
atinit''
,atload''
, etc.make
make
command after cloning/updating and executing mv
, cp
, atpull
, atclone
Ice mods. Can obtain argument, e.g. make"install PREFIX=/opt"
. If the value starts with !
then make
is ran before atclone
/atpull
, e.g. make'!'
.countdown
atclone''
,atpull''
and make
icesreset
git reset --hard HEAD
for plugins or svn revert
for SVN snippets before pulling any new changes. This way git
or svn
will not report conflicts if some changes were done in e.g.: atclone''
ice. For file snippets and gh-r
plugins it invokes rm -rf *
.Sticky-Emulation Of Other Shells
Modifier Descriptionsh
, !sh
sh
emulation so that also all functions declared within the file will get a sticky emulation assigned – when invoked they'll execute also with the sh
emulation set-up. The !sh
version switches additional options that are rather not important from the portability perspective.bash
, !bash
sh
, but with the SH_GLOB
option disabled, so that Bash regular expressions work.ksh
, !ksh
sh
, but emulating ksh
shell.csh
, !csh
sh
, but emulating csh
shell.Others
Modifier Descriptionas
as"program"
(also the alias: as"command"
), and will cause to add script/program to $PATH
instead of sourcing (see pick
). Can also be as"completion"
– use with plugins or snippets in whose only underscore-starting _*
files you are interested in. The third possible value is as"null"
– a shorthand for pick"/dev/null" nocompletions
– i.e.: it disables the default script-file sourcing and also the installation of completions.id-as
compile
{...}
expansion, like {a/*,b*}
) to select additional files to compile, e.g. compile"(pure|async).zsh"
for sindresorhus/pure
.nocompile
pick
-pointed files. If passed the exclamation mark (i.e. nocompile'!'
), then do compile, but after make''
and atclone''
(useful if Makefile installs some scripts, to point pick''
at the location of their installation).service
reset-prompt
zle .reset-prompt
). Note: normally it's sufficient to precede the value of wait''
ice with !
.bindmap
;
-separated strings like Key(s)A -> Key(s)B
, e.g. ^R -> ^T; ^A -> ^B
. In general, bindmap''
changes bindings (done with the bindkey
builtin) the plugin does. The example would cause the plugin to map Ctrl-T instead of Ctrl-R, and Ctrl-B instead of Ctrl-A. Does not work with snippets.trackbinds
bindkey
calls even with zinit light ...
, i.e. even with investigating disabled (fast loading), to allow bindmap
to remap the key-binds. The same effect has zinit light -b ...
, i.e. additional -b
option to the light
-subcommand. Does not work with snippets.wrap-track
;
-separated list of function names that are to be investigated (meaning gathering report and unload data) once during execution. It works by wrapping the functions with a investigating-enabling and disabling snippet of code. In summary, wrap-track
allows to extend the investigating beyond the moment of loading of a plugin. Example use is to wrap-track
a precmd function of a prompt (like _p9k_precmd()
of powerlevel10k) or other plugin that postpones its initialization till the first prompt (like e.g.: zsh-autosuggestions). Does not work with snippets.aliases
light-mode
light
command. Useful for the for-syntax, where there is no load
nor light
subcommandextract
zip
, tar.gz
, etc. and also notably OS X dmg
images. If it has no value, then it works in the auto mode – it automatically extracts all files of known archive extensions IF they aren't located deeper than in a sub-directory (this is to prevent extraction of some helper archive files, typically located somewhere deeper in the tree). If no such files will be found, then it extracts all found files of known type – the type is being read by the file
Unix command. If not empty, then takes names of the files to extract. Refer to the Wiki page for further information.subst
zinit subst'autoload → autoload -Uz' …
.autoload
atinit'autoload the-function'
. Supports renaming of the function – pass '… → new-name'
or '… -> new-name'
, e.g.: zinit autoload'fun → my-fun; fun2 → my-fun2'
.Order of Execution
Order of execution of related Ice-mods: atinit
-> atpull!
-> make'!!'
-> mv
-> cp
-> make!
-> atclone
/atpull
-> make
-> (plugin script loading)
-> src
-> multisrc
-> atload
.
Zinit Commands
Following commands are passed to zinit ...
to obtain described effects.
Command
Description
-h, --help, help
man
Loading and Unloading
Command Descriptionload {plg-spec}
light [-b] {plg-spec}
-b
– investigate bindkey
-calls only. There's also light-mode
ice which can be used to induce the no-investigating (i.e.: light) loading, regardless of the command used.unload [-q] {plg-spec}
zinit load ...
. -q
– quiet.snippet [-f] {url}
-f
– don't use cache (force redownload). The URL can use the following shorthands: PZT::
(Prezto), PZTM::
(Prezto module), OMZ::
(Oh My Zsh), OMZP::
(OMZ plugin), OMZL::
(OMZ library), OMZT::
(OMZ theme), e.g.: PZTM::environment
, OMZP::git
, etc.Completions
Command Description clist [columns], completions [columns]
columns
completions per line. zpl clist 5
will for example print 5 completions per line. Default is 3.cdisable {cname}
cname
.cenable {cname}
cname
.creinstall [-q] [-Q] {plg-spec}
-q
– quiet. -Q
- quiet all.cuninstall {plg-spec}
csearch
compinit
cclear
cdlist
cdreplay [-q]
-q
– quiet.cdclear [-q]
-q
– quiet.Tracking of the Active Session
Command Descriptiondtrace, dstart
dstop
dunload
dreport
dclear
Reports and Statistics
Command Descriptiontimes [-s] [-m]
-s
– use seconds instead of milliseconds. -m
– show plugin loading moments.zstatus
report {plg-spec}|--all
--all
– do it for all plugins.loaded [keyword], list [keyword]
ls
status {plg-spec}|URL|--all
--all
– do it for all plugins and snippets.recently [time-spec]
bindkeys
Compiling
Command Descriptioncompile {plg-spec}|--all
--all
– compile all plugins.uncompile {plg-spec}|--all
--all
– do it for all plugins.compiled
Other
Command Descriptionself-update
update [-q] [-r] {plg-spec}|URL|--all
--all
– update all plugins and snippets.-q
– quiet.-r
| --reset
– run git reset --hard
/ svn revert
before pulling changes.ice <ice specification>
delete {plg-spec}|URL|--clean|--all
--all
– purge.--clean
– delete plugins and snippets that are not loaded.cd {plg-spec}
edit {plg-spec}
glance {plg-spec}
stress {plg-spec}
changes {plg-spec}
create {plg-spec}
srv {service-id} [cmd]
next
moves the service to another Zshell.recall {plg-spec}|URL
zinit ice ...
command.env-whitelist [-v] [-h] {env..}
-v
– verbose.module
zinit module help
.add-fpath|fpath
[-f|--front]
{plg-spec}
[subdirectory]
$fpath
. If the second argument is given, it is appended to the directory path. If the option -f
/--front
is given, the directory path is prepended instead of appended to $fpath
. The {plg-spec}
can be absolute path, i.e.: it's possible to also add regular directories.run
[-l]
[plugin]
{command}
-l
will be given then the plugin should be skipped – the option will cause the previous plugin to be reused.Updating Zinit and Plugins
To update Zinit issue zinit self-update
in the command line.
To update all plugins and snippets, issue zinit update
. If you wish to update only
a single plugin/snippet instead issue zinit update NAME_OF_PLUGIN
. A list of
commits will be shown:
Some plugins require performing an action each time they're updated. One way you can do
this is by using the atpull
ice modifier. For example, writing zinit ice atpull'./configure'
before loading a plugin will execute ./configure
after a successful update. Refer to Ice Modifiers for more information.
The ice modifiers for any plugin or snippet are stored in their directory in a
._zinit
subdirectory, hence the plugin doesn't have to be loaded to be correctly
updated. There's one other file created there, .zinit_lstupd
– it holds the log of
the new commits pulled-in in the last update.
Completions
Calling compinit
Without Turbo Mode
With no Turbo mode in use, compinit can be called normally, i.e.: as autoload compinit; compinit
. This should be done after loading of all plugins and before possibly calling
zinit cdreplay
.
The cdreplay
subcommand is provided to re-play all catched compdef
calls. The
compdef
calls are used to define a completion for a command. For example, compdef _git git
defines that the git
command should be completed by a _git
function.
The compdef
function is provided by compinit
call. As it should be called later,
after loading all of the plugins, Zinit provides its own compdef
function that
catches (i.e.: records in an array) the arguments of the call, so that the loaded
plugins can freely call compdef
. Then, the cdreplay
(compdef-replay) can be used,
after compinit
will be called (and the original compdef
function will become
available), to execute all detected compdef
calls. To summarize:
source ~/.zinit/bin/zinit.zsh zinit load "some/plugin" ... compdef _gnu_generic fd # this will be intercepted by Zinit, because as the compinit # isn't yet loaded, thus there's no such function `compdef'; yet # Zinit provides its own `compdef' function which saves the # completion-definition for later possible re-run with `zinit # cdreplay' or `zicdreplay' (the second one can be used in hooks # like atload'', atinit'', etc.) ... zinit load "other/plugin" autoload -Uz compinit compinit zinit cdreplay -q # -q is for quiet; actually run all the `compdef's saved before #`compinit` call (`compinit' declares the `compdef' function, so # it cannot be used until `compinit' is ran; Zinit solves this # via intercepting the `compdef'-calls and storing them for later # use with `zinit cdreplay')
This allows to call compinit once.
Performance gains are huge, example shell startup time with double compinit
: 0.980 sec, with
cdreplay
and single compinit
: 0.156 sec.
Calling compinit
With Turbo Mode
If you load completions using wait''
Turbo mode then you can add
atinit'zicompinit'
to syntax-highlighting plugin (which should be the last
one loaded, as their (2 projects, z-sy-h &
f-sy-h)
documentation state), or atload'zicompinit'
to last
completion-related plugin. zicompinit
is a function that just runs autoload compinit; compinit
, created for convenience. There's also zicdreplay
which
will replay any caught compdefs so you can also do: atinit'zicompinit; zicdreplay'
, etc. Basically, the whole topic is the same as normal compinit
call,
but it is done in atinit
or atload
hook of the last related plugin with use of the
helper functions (zicompinit
,zicdreplay
& zicdclear
– see below for explanation
of the last one). To summarize:
source ~/.zinit/bin/zinit.zsh # Load using the for-syntax zinit wait lucid for \ "some/plugin" zinit wait lucid for \ "other/plugin" zinit wait lucid atload"zicompinit; zicdreplay" blockf for \ zsh-users/zsh-completions
Ignoring Compdefs
If you want to ignore compdefs provided by some plugins or snippets, place their load commands
before commands loading other plugins or snippets, and issue zinit cdclear
(or
zicdclear
, designed to be used in hooks like atload''
):
source ~/.zinit/bin/zinit.zsh zinit snippet OMZP::git zinit cdclear -q # <- forget completions provided by Git plugin zinit load "some/plugin" ... zinit load "other/plugin" autoload -Uz compinit compinit zinit cdreplay -q # <- execute compdefs provided by rest of plugins zinit cdlist # look at gathered compdefs
The cdreplay
is important if you use plugins like
OMZP::kubectl
or asdf-vm/asdf
, because these plugins call
compdef
.
Disabling System-Wide compinit
Call (Ubuntu)
On Ubuntu users might get surprised that e.g. their completions work while they didn't
call compinit
in their .zshrc
. That's because the function is being called in
/etc/zshrc
. To disable this call – what is needed to avoid the slowdown and if user
loads any completion-equipped plugins, i.e. almost on 100% – add the following lines to
~/.zshenv
:
# Skip the not really helping Ubuntu global compinit skip_global_compinit=1
Zinit Module
Motivation
The module is a binary Zsh module (think about zmodload
Zsh command, it's that topic) which transparently and
automatically compiles sourced scripts. Many plugin managers do not offer compilation of plugins, the module is
a solution to this. Even if a plugin manager does compile plugin's main script (like Zinit does), the script can
source smaller helper scripts or dependency libraries (for example, the prompt geometry-zsh/geometry
does that)
and there are very few solutions to that, which are demanding (e.g. specifying all helper files in plugin load
command and investigating updates to the plugin – in Zinit case: by using compile
ice-mod).
Installation
Without Zinit
To install just the binary Zinit module standalone (Zinit is not needed, the module can be used with any other plugin manager), execute:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma-continuum/zinit/master/doc/mod-install.sh)"
This script will display what to add to ~/.zshrc
(2 lines) and show usage instructions.
With Zinit
Zinit users can build the module by issuing following command instead of running above mod-install.sh
script
(the script is for e.g. zgen
users or users of any other plugin manager):
zinit module build
This command will compile the module and display instructions on what to add to ~/.zshrc
.
Measuring Time of source
s
Besides the compilation-feature, the module also measures duration of each script sourcing. Issue zpmod source-study
after loading the module at top of ~/.zshrc
to see a list of all sourced files with the time the
sourcing took in milliseconds on the left. This feature allows to profile the shell startup. Also, no script can
pass-through that check and you will obtain a complete list of all loaded scripts, like if Zshell itself was
investigating this. The list can be surprising.
Debugging
To enable debug messages from the module set:
typeset -g ZPLG_MOD_DEBUG=1
Hints and Tips
Customizing Paths
Following variables can be set to custom values, before sourcing Zinit. The
previous global variables like $ZPLG_HOME
have been removed to not pollute
the namespace – there's single $ZINIT
hash instead of 8
string
variables. Please update your dotfiles.
declare -A ZINIT # initial Zinit's hash definition, if configuring before loading Zinit, and then:
.zcompdump
file, with the file included (i.e. its name can be different)
ZINIT[COMPINIT_OPTS]
Options for compinit
call (i.e. done by zicompinit
), use to pass -C to speed up loading
ZINIT[MUTE_WARNINGS]
If set to 1
, then mutes some of the Zinit warnings, specifically the plugin already registered
warning
ZINIT[OPTIMIZE_OUT_DISK_ACCESSES]
If set to 1
, then Zinit will skip checking if a Turbo-loaded object exists on the disk. By default Zinit skips Turbo for non-existing objects (plugins or snippets) to install them before the first prompt – without any delays, during the normal processing of zshrc
. This option can give a performance gain of about 10 ms out of 150 ms (i.e.: Zsh will start up in 140 ms instead of 150 ms).
There is also $ZPFX
, set by default to ~/.zinit/polaris
– a directory
where software with Makefile
, etc. can be pointed to, by e.g. atclone'./configure --prefix=$ZPFX'
.
Non-GitHub (Local) Plugins
Use create
subcommand with user name _local
(the default) to create plugin's
skeleton in $ZINIT[PLUGINS_DIR]
. It will be not connected with GitHub repository
(because of user name being _local
). To enter the plugin's directory use cd
command
with just plugin's name (without _local
, it's optional).
If user name will not be _local
, then Zinit will create repository also on GitHub
and setup correct repository origin.
Extending Git
There are several projects that provide git extensions. Installing them with Zinit has many benefits:
- all files are under
$HOME
– no administrator rights needed, - declarative setup (like Chef or Puppet) – copying
.zshrc
to different account brings also git-related setup, - easy update by e.g.
zinit update --all
.
Below is a configuration that adds multiple git extensions, loaded in Turbo mode, 1 second after prompt, with use of the Bin-Gem-Node annex:
zinit as"null" wait"1" lucid for \ sbin Fakerr/git-recall \ sbin cloneopts paulirish/git-open \ sbin paulirish/git-recent \ sbin davidosomething/git-my \ sbin atload"export _MENU_THEME=legacy" \ arzzen/git-quick-stats \ sbin iwata/git-now \ make"PREFIX=$ZPFX install" \ tj/git-extras \ sbin"git-url;git-guclone" make"GITURL_NO_CGITURL=1" \ zdharma-continuum/git-url
Target directory for installed files is $ZPFX
(~/.zinit/polaris
by default).
Supporting
Zinit is a personal, free-time project with no funding and a huge feature request backlog. If you love it, consider supporting its development via GitHub Sponsors or Patreon. Any help counts!
Getting Help and Community
Do you need help or wish to get in touch with other Zinit users?
-
Visit our subreddit r/zinit.
-
Or via Gitter
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK