From 7c222d34bda95c5d041d69fbce641c1910369c3f Mon Sep 17 00:00:00 2001 From: Man Nguyen Date: Sat, 2 Sep 2023 18:18:51 +0700 Subject: [PATCH 1/3] feat: support glob pattern --- README.md | 3 +++ zap.zsh | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f588ae5..59dd951 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 folder (must match pattern *.{plugin.,}{z,}sh{-theme,}) +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 671d2f2..7909d8a 100644 --- a/zap.zsh +++ b/zap.zsh @@ -4,16 +4,25 @@ export ZSHRC="${ZDOTDIR:-$HOME}/.zshrc" export ZAP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/zap" export ZAP_PLUGIN_DIR="$ZAP_DIR/plugins" export -a ZAP_INSTALLED_PLUGINS=() -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) + ) + (( $#initfiles )) && source $initfiles[1] + fi } # If the absolute is a directory then source as a local plugin @@ -24,6 +33,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 From c7f45f49fdbc6b7e982759660afe7d4dec95d932 Mon Sep 17 00:00:00 2001 From: Marco <82162277+mamaraddio@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:40:26 +0200 Subject: [PATCH 2/3] Update README.md fix: fix example message to clarify the use of this feature --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59dd951..efb407e 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ plug "$HOME/plugins/my-custom-prompt" plug "$HOME/.config/zsh/aliases.zsh" plug "$HOME/.config/zsh/exports.zsh" -# Example install all local plugin in folder (must match pattern *.{plugin.,}{z,}sh{-theme,}) +# Example install all local plugin in a folder (must be an absolute path anding with *) plug "$HOME/plugins/*" ``` From 048a43e5cd25c221e96554fd71b812b62b9cf4c0 Mon Sep 17 00:00:00 2001 From: Marco <82162277+mamaraddio@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:49:24 +0200 Subject: [PATCH 3/3] 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 --- zap.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zap.zsh b/zap.zsh index 7909d8a..fd38e03 100644 --- a/zap.zsh +++ b/zap.zsh @@ -4,6 +4,7 @@ export ZSHRC="${ZDOTDIR:-$HOME}/.zshrc" export ZAP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/zap" export ZAP_PLUGIN_DIR="$ZAP_DIR/plugins" export -a ZAP_INSTALLED_PLUGINS=() +fpath+="$ZAP_DIR/completion" function plug() { @@ -20,6 +21,7 @@ function plug() { # 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