From 933eb407ae77e169a74cb47c20efeb376ae124d2 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Sun, 16 Apr 2023 08:57:24 -0400 Subject: [PATCH] feat: Speed up plugin source file detection --- zap.zsh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/zap.zsh b/zap.zsh index cbc4425..4041f27 100644 --- a/zap.zsh +++ b/zap.zsh @@ -9,14 +9,11 @@ fpath+="$ZAP_DIR/completion" function plug() { function _try_source() { - typeset -a extensions=(".plugin.zsh" ".zsh-theme" ".zsh") - for ext in "${extensions[@]}"; do - [[ -e "$plugin_dir/$plugin_name$ext" ]] && source "$plugin_dir/$plugin_name$ext" && return 0 - [[ -e "$plugin_dir/${plugin_name#zsh-}$ext" ]] && source "$plugin_dir/${plugin_name#zsh-}$ext" && return 0 - # If the plugin file has a different name than $plugin_name - plugin_filename=$(command ls $plugin_dir | grep $ext) - [[ -n $plugin_filename ]] && [[ $(echo $plugin_filename | wc -l) -eq 1 ]] && source "$plugin_dir/$plugin_filename" && return 0 - done + local -a initfiles=( + $plugin_dir/${plugin_name}.{plugin.,}{z,}sh{-theme,}(N) + $plugin_dir/*.{plugin.,}{z,}sh{-theme,}(N) + ) + (( $#initfiles )) && source $initfiles[1] } # If the absolute is a directory then source as a local plugin