zsh:autoload: Load wrapper only if command exists

This commit is contained in:
2025-03-25 10:46:50 +01:00
parent 071c2866e5
commit cd54c3dfed
2 changed files with 14 additions and 1 deletions

View File

@@ -9,8 +9,21 @@ autoload -Uz run-help run-help-git zmv
# Load autoloadable functions # Load autoloadable functions
if [[ -d "$ZDOTDIR/autoload" ]]; then if [[ -d "$ZDOTDIR/autoload" ]]; then
# Include all subdirectories # Include all wrapper scripts if their wrapped command exists
d="$ZDOTDIR/autoload/wrapper"
if [[ -d "$d" ]]; then
fpath=("$d" $fpath)
for f in "$d"/[^_.]*(.xN:t); do
(( $+commands[$f] )) || continue
autoload -Uz -- "$f"
done
fi
# Include all other subdirectories
for d in "$ZDOTDIR/autoload/"*(/N); do for d in "$ZDOTDIR/autoload/"*(/N); do
# EXTENDED_GLOB is not yet set, so we have to exclude manually
[[ ${d:t} != wrapper ]] || continue
fpath=("$d" $fpath) fpath=("$d" $fpath)
autoload -Uz -- "" "$d"/[^_.]*(.xN:t) autoload -Uz -- "" "$d"/[^_.]*(.xN:t)
done done