From cd54c3dfed57ceb5645218779431afd394836542 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 25 Mar 2025 10:46:50 +0100 Subject: [PATCH] zsh:autoload: Load wrapper only if command exists --- .config/zsh/autoload/{ => wrapper}/clang-format | 0 .config/zsh/zshrc.d/00-autoload.zsh | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) rename .config/zsh/autoload/{ => wrapper}/clang-format (100%) diff --git a/.config/zsh/autoload/clang-format b/.config/zsh/autoload/wrapper/clang-format similarity index 100% rename from .config/zsh/autoload/clang-format rename to .config/zsh/autoload/wrapper/clang-format diff --git a/.config/zsh/zshrc.d/00-autoload.zsh b/.config/zsh/zshrc.d/00-autoload.zsh index f7bf0c0..bb32561 100644 --- a/.config/zsh/zshrc.d/00-autoload.zsh +++ b/.config/zsh/zshrc.d/00-autoload.zsh @@ -9,8 +9,21 @@ autoload -Uz run-help run-help-git zmv # Load autoloadable functions 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 + # EXTENDED_GLOB is not yet set, so we have to exclude manually + [[ ${d:t} != wrapper ]] || continue + fpath=("$d" $fpath) autoload -Uz -- "" "$d"/[^_.]*(.xN:t) done