Difference between zmodload vs. autoload in Zsh

Viewed 812

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
1 Answers

Zsh's manuals do explain the difference (albeit not in one place):

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.

Related