I wasn't able to find a documentation for the widely used autoload
command in zsh. Does anybody can explain it in plain English?
A bit more specific: What does autoloading of modules mean, for example in this line:
autoload -Uz vcs_info
What does it do?
I've tried autoload --help
, man autoload
, googling - no success. Thanks!
The
autoload
feature is not available in bash, but it is inksh
(korn shell) andzsh
. Onzsh
seeman zshbuiltins
.Functions are called in the same way as any other command. There can be a name conflict between a program and a function. What
autoload
does is to mark that name as being a function rather than an external program. The function has to be in a file on its own, with the filename the same as the function name.The
-U
means mark the functionvcs_info
for autoloading and suppress alias expansion. The-z
means usezsh
(rather thanksh
) style. See also thefunctions
command.Edit (from comment, as suggested by @ijoseph):
So it records the fact that the name is a function and not an external program - it does not call it unless the
-X
option is used, it just affects the search path when it is called. If the function name does not collide with the name of a program then it is not required. Prefix your functions with something likef_
and you will probably never need it.For more detail see http://zsh.sourceforge.net/Doc/Release/Functions.html.