mirror of
https://github.com/zdharma-continuum/zinit-annex-meta-plugins.git
synced 2026-09-10 07:16:29 -04:00
162 lines
6.5 KiB
Bash
162 lines
6.5 KiB
Bash
#!/usr/bin/env zsh
|
||
# -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||
|
||
# Copyright (c) 2020 Sebastian Gniazdowski
|
||
|
||
za-meta-plugins-before-load-handler() {
|
||
|
||
# Set the base and typically useful options.
|
||
builtin emulate -LR zsh
|
||
builtin setopt extendedglob warncreateglobal typesetsilent noshortloops rcquotes
|
||
|
||
local type=$1 id=$2 id_as=$3 args=$4 ices=$5 hook=$6 subtype=$7
|
||
|
||
if (( $+ICE[debug] )) {
|
||
# Enable the output from this annex
|
||
integer ibshow_messages=1 ibdebug=1
|
||
}
|
||
|
||
# Apply the default ices first.
|
||
local -a ices
|
||
ices=( "${(@Q)${(@z)Zinit_Annex_Meta_Plugins[default-ices]}}" )
|
||
(( ${#ices} > 0 && ${#ices} % 2 == 0 )) && ICE=( "${(@kv)ICE}" "${ices[@]}" )
|
||
|
||
# Exclude IDs with slashes and also packages
|
||
[[ $id == */* ]] && local bad_id=1
|
||
[[ $id == *:* ]] && local bad_id2=1
|
||
[[ $ICE[teleid] == */* ]] && local bad_tele=1
|
||
(( $+ICE[pack] )) && local is_pack=1
|
||
if (( bad_id || bad_id2 || bad_tele || is_pack )) {
|
||
if (( ibdebug )) {
|
||
local -a msgs
|
||
msgs=( ${bad_id:+the ID contains a slash} ${bad_id2:+the ID looks like a snippet ID}
|
||
${bad_tele:+"the {ice}teleid{meta}''{msg} ice contains a slash"}
|
||
${is_pack:+"the ID is a package ↔ {ice}pack{meta}''{msg} ice given"} )
|
||
+zinit-message "{pre}meta-plugins annex: {msg}Skipping the ID: {meta2}$id{msg}" \
|
||
"(reason(s): ${(j:, :)msgs}).{rst}"
|
||
}
|
||
return 0
|
||
}
|
||
|
||
integer ibshow_messages iberror_flag
|
||
local -a match mbegin mend reply
|
||
local MATCH REPLY
|
||
integer MBEGIN MEND
|
||
|
||
local -A tpe_map
|
||
tpe_map=( 0 plugin 1 snippet )
|
||
|
||
# Reset the communication fields.
|
||
ZINIT[annex-before-load:new-@]=""
|
||
ZINIT[annex-before-load:new-global-ices]=""
|
||
|
||
# Strip the ID from some possible accidental /-s.
|
||
id=${${id#@}%%(///|//|/)}
|
||
|
||
local meta_plugin_data=${(v)Zinit_Annex_Meta_Plugins_Map[$id]}
|
||
|
||
if [[ -n $meta_plugin_data ]] {
|
||
# Count the recognized meta-plugins
|
||
Zinit_Annex_Meta_Plugins_Map[recon-count]=$(( Zinit_Annex_Meta_Plugins_Map[recon-count] + 1 ))
|
||
|
||
local -a plugin_array loaded_plugins not_existing on_demand_cand on_demand_skip
|
||
plugin_array=( ${(s: :)meta_plugin_data} )
|
||
loaded_plugins=( ${(@Q)${(@z)Zinit_Annex_Meta_Plugins[annex-loaded-plugins]}} )
|
||
|
||
local p
|
||
|
||
# Detect if any plugins should be skipped on-demand, via skip''.
|
||
on_demand_cand=( ${(@)${(@ps:\t:)${(@s: :)${(@s.;.)ICE[skip]}}}} )
|
||
for p ( $on_demand_cand ) {
|
||
integer idx1 count=1
|
||
local pattern="(*/$p*|$p*|*$p|*-$p*|*$p-*)"
|
||
while (( (idx1 = $plugin_array[(in:count:)$pattern]) != ${#plugin_array} + 1 )) {
|
||
count+=1
|
||
on_demand_skip+=( $plugin_array[idx1] )
|
||
}
|
||
}
|
||
|
||
# Check if any plugins are missing on the disk.
|
||
for p ( ${plugin_array:|on_demand_skip} ) {
|
||
if [[ -z $Zinit_Annex_Meta_Plugins_Map[$p] ]] && \
|
||
! .zinit-get-object-path AUTO $p
|
||
then
|
||
ibshow_messages=1
|
||
not_existing+=( $p )
|
||
fi
|
||
}
|
||
|
||
# Debug message.
|
||
if (( ibshow_messages )) {
|
||
(($+functions[.zinit-two-paths])) || builtin source $ZINIT[BIN_DIR]/zinit-side.zsh
|
||
|
||
# Output a separating newline if the previous-processed
|
||
# plugin isn't a meta-plugin → to cluster the messages.
|
||
[[ -z $Zinit_Annex_Meta_Plugins_Map[${ZINIT[annex-exposed-processed-IDs]##* }] ]] && builtin print
|
||
|
||
+zinit-message -n "{hi}$Zinit_Annex_Meta_Plugins_Map[recon-count].{rst} "
|
||
+zinit-message -n "{pre}[meta-plugins annex]{msg} Loading" \
|
||
"{b}{meta2}meta-plugin{ehi}: {rst}{msg}\`{meta}{b}$id{rst}{msg}'" \
|
||
"consisting of{ehi}:{rst}"
|
||
integer count
|
||
local -a skipped
|
||
for p ( $plugin_array ) {
|
||
count+=1
|
||
.zinit-any-colorify-as-uspl2 $p
|
||
[[ $p = $plugin_array[-1] ]] && local enotlast= || local enotlast=0
|
||
REPLY=${REPLY//\//∕}
|
||
|
||
integer idx1=0 idx2=0 idx3=0
|
||
if (( ((idx1 = $loaded_plugins[(I)$p]) || (idx2 = $zsh_loaded_plugins[(I)$p])) && \
|
||
! $not_existing[(I)$p] || (idx3 = $on_demand_skip[(I)$p])
|
||
)) && [[ $p != zdharma-continuum/null ]] {
|
||
idx3=$on_demand_skip[(I)$p]
|
||
local idtxt="{dbg}${p//\//∕} "
|
||
if (( (idx1 || idx2) && !idx3 )) {
|
||
skipped+=( $REPLY )
|
||
idtxt+="{warn}a/l{rst}"
|
||
} else {
|
||
idtxt+="{warn}skip{rst}"
|
||
}
|
||
REPLY=$idtxt
|
||
}
|
||
|
||
+zinit-message -n " {b}$count{rst}{msg}) $REPLY{msg}${enotlast:+,}"
|
||
}
|
||
+zinit-message ".{rst}"
|
||
if (( ibdebug && ${#skipped} )) {
|
||
+zinit-message -n "{hi}$Zinit_Annex_Meta_Plugins_Map[recon-count].{rst} "
|
||
+zinit-message "{pre}[meta-plugins annex]{msg} Skipping already" \
|
||
"loaded: ${(j:, :)skipped}{msg}.{rst}"
|
||
}
|
||
}
|
||
|
||
# Pre-process each plugin retrieving the assigned, default
|
||
# ice-lists and preparing the above communication fields.
|
||
for p ( $plugin_array ) {
|
||
local ice_list_data=$Zinit_Annex_Meta_Plugins_Config_Map[$p]
|
||
if (( ( $not_existing[(I)$p] || \
|
||
! ($loaded_plugins[(I)$p] || $zsh_loaded_plugins[(I)$p]) ) && \
|
||
! $on_demand_skip[(I)$p]
|
||
)) || [[ $p == zdharma-continuum/null ]] {
|
||
# The ↑zdharma-continuum/null↑ is a bogus exception, as this plugin will never
|
||
# be loaded under the direct name.
|
||
ZINIT[annex-before-load:new-@]+="$ice_list_data @${(q)p} "
|
||
Zinit_Annex_Meta_Plugins[annex-loaded-plugins]+=" ${(q)p}"
|
||
}
|
||
}
|
||
ZINIT[annex-before-load:new-@]+=" $args"
|
||
ZINIT[annex-before-load:new-@]=${ZINIT[annex-before-load:new-@]## ##}
|
||
# Setting to 1 here will prevent the error message
|
||
# on no plugin/snippet ID given.
|
||
integer retval_part=${${ZINIT[annex-before-load:new-@]:+2}:-1}
|
||
} else {
|
||
integer retval_part=0
|
||
}
|
||
|
||
return $(( ${${ZINIT[annex-before-load:new-global-ices]:+4}:-0} + \
|
||
retval_part + iberror_flag ))
|
||
}
|
||
|
||
# vim:ft=zsh:tw=80:sw=4:sts=4:et
|