What is the difference between commands zmodload
and autoload
in Zsh? They seem to be doing similar things and the manuals don't say much. Example:
zmodload zsh/terminfo
vs.
autoload -U zsh/terminfo
Zsh's manuals do explain the difference (albeit not in one place):
zmodload
loads a module supplied with Zsh itself. Modules are written in the C programming language.autoload
declares a function to be loaded on demand from your $fpath
. Functions are written in Zsh’s own shell script language.Since zsh/terminfo
is a Zsh-supplied module, you should use zmodload
to load it (and not autoload
). Autoloading zsh/terminfo
won’t do anything, because it’s not a function and it’s not written in shell script.
Note, that on most distributions of Zsh (such as the one included with macOS), certain Zsh modules are loaded dynamically when you try to use them, so you won’t even need zmodload
. However, it’s not documented which ones and if you’re writing functions or scripts that are intended for wider distribution, then you cannot rely on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With