From 5eb155616807b1c8e0be6d77a7ad1008d63d4518 Mon Sep 17 00:00:00 2001 From: Man Nguyen <9559161+mannguyen0107@users.noreply.github.com> Date: Tue, 9 Apr 2024 18:04:13 +0700 Subject: [PATCH] feat: support glob pattern (#172) * feat: support glob pattern * Update README.md fix: fix example message to clarify the use of this feature * fix: fix two lines - put back in place the `fpath` line - fixed original functionality allowing the plugin `initfile` to have a different name from the plugin repository --------- Co-authored-by: Man Nguyen Co-authored-by: Marco <82162277+mamaraddio@users.noreply.github.com> --- README.md | 3 +++ zap.zsh | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bc442bc..32546bd 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,9 @@ plug "$HOME/plugins/my-custom-prompt" # Example sourcing of local files plug "$HOME/.config/zsh/aliases.zsh" plug "$HOME/.config/zsh/exports.zsh" + +# Example install all local plugin in a folder (must be an absolute path anding with *) +plug "$HOME/plugins/*" ``` By default `Zap` when installing a plugin will clone a GitHub repository using a HTTPS web URL, if you require to be able to install from a private GitHub or from a different git server (for example GitLab) you can provide a different URL prefix to be used. For example: diff --git a/zap.zsh b/zap.zsh index e9f494d..ac4e02f 100644 --- a/zap.zsh +++ b/zap.zsh @@ -9,11 +9,22 @@ fpath+="$ZAP_DIR/completion" function plug() { function _try_source() { - local -a initfiles=( - $plugin_dir/${plugin_name}.{plugin.,}{z,}sh{-theme,}(N) - $plugin_dir/*.{plugin.,}{z,}sh{-theme,}(N) - ) - (( $#initfiles )) && source $initfiles[1] + if [[ "$plugin_name" == "*" ]]; then + # Treat * as a glob pattern + local -a initfiles=( + $plugin_dir/*.{plugin.,}{z,}sh{-theme,}(N) + ) + for file in "${initfiles[@]}"; do + [[ -f "$file" ]] && source "$file" + done + else + # Use the specified plugin_name + local -a initfiles=( + $plugin_dir/${plugin_name}.{plugin.,}{z,}sh{-theme,}(N) + $plugin_dir/*.{plugin.,}{z,}sh{-theme,}(N) + ) + (( $#initfiles )) && source $initfiles[1] + fi } # If the absolute is a directory then source as a local plugin @@ -24,6 +35,9 @@ function plug() { local plugin="${plugin_absolute}" local plugin_name="${plugin:t}" local plugin_dir="${plugin_absolute}" + elif [ "${plugin_absolute:t}" = "*" ]; then + local plugin_name="${plugin_absolute:t}" + local plugin_dir="${plugin_absolute:h}" else # If the basename directory exists, then local source only if [ -d "${plugin_absolute:h}" ]; then