Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between zmodload vs. autoload in Zsh

Tags:

shell

zsh

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
like image 878
Joohwan Avatar asked Oct 12 '25 11:10

Joohwan


1 Answers

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.

like image 55
Marlon Richert Avatar answered Oct 16 '25 06:10

Marlon Richert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!