What is the difference between `autoload` and `autoload -U` in Zsh?

What is the difference between autoload -U and plain autoload?

For instance, here it is recommended to run:

autoload -U run-help
autoload run-help-git
autoload run-help-svn
autoload run-help-svk
unalias run-help
alias help=run-help

Why is -U only in the first line?

Asked By: shadowtalker


Yes, you do see the recommendation for -U often, usually paired with -z. It’s not documented in the run-help for autoload, but there is a section titled “AUTOLOADING FUNCTIONS” in the manpage for zshmisc.

There it states:

The usual alias expansion during reading will be suppressed if the autoload
builtin or its equivalent is given the option -U. This is recommended for the
use of functions supplied with the zsh distribution. Note that for functions
precompiled with the zcompile builtin command the flag -U must be provided
when the .zwc file is created, as the corresponding information is compiled
into the latter.

I read that as “disregard aliases”. The -z seems to be to avoid Ksh-isms. I just memorize -Uz and usually add them to any autoload. Maybe a worthwhile alias: alias al=’autoload -Uz’.

See also: https://stackoverflow.com/questions/12570749/zsh-completion-difference

Answered By: Micah Elliott
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.