Skip to content

Commit

Permalink
feat: support glob pattern (#172)
Browse files Browse the repository at this point in the history
* 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 <man.nguyen@localhost>
Co-authored-by: Marco <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent 168a05a commit 5eb1556
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 19 additions & 5 deletions zap.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5eb1556

Please sign in to comment.