Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support glob pattern #172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading