@@ -528,78 +528,74 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
528528# $1 - plugin spec (4 formats: user---plugin, user/plugin, user, plugin)
529529# $2 - plugin if $1 (i.e., user) given
530530# $3 - if 1, then reinstall, otherwise only install completions that are not present
531- .zinit-install-completions() {
531+ .zinit-install-completions () {
532532 builtin emulate -LR zsh ${=${options[xtrace]:#off}:+-o xtrace}
533- setopt nullglob extendedglob warncreateglobal typesetsilent noshortloops
533+ setopt extended_glob no_short_loops null_glob typeset_silent warn_create_global
534+
535+ local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}}
536+ local reinstall=${3:-0} quiet=${${4:+1}:-0}
537+
538+ (( OPTS[opt_-q,--quiet] )) && quiet=1
539+ [[ $4 = -Q ]] && quiet=2
534540
535- local id_as=$1${2:+${${${(M)1:#%}:+$2}:-/$2}}
536- local reinstall=${3:-0} quiet=${${4:+1}:-0}
537- (( OPTS[opt_-q,--quiet] )) && quiet=1
538- [[ $4 = -Q ]] && quiet=2
539541 typeset -ga INSTALLED_COMPS SKIPPED_COMPS
540- INSTALLED_COMPS=() SKIPPED_COMPS=()
542+ INSTALLED_COMPS=() SKIPPED_COMPS=()
541543
542544 .zinit-any-to-user-plugin "$id_as" ""
543- local user=${reply[-2]}
544- local plugin=${reply[-1]}
545+ local user=${reply[-2]}
546+ local plugin=${reply[-1]}
545547 .zinit-any-colorify-as-uspl2 "$user" "$plugin"
546- local abbrev_pspec=$REPLY
547-
548+ local abbrev_pspec=$REPLY
548549 .zinit-exists-physically-message "$id_as" "" || return 1
549-
550- # Symlink any completion files included in the plugin directory
551550 typeset -a completions already_symlinked backup_comps
552551 local c cfile bkpfile
553- # The plugin == . is a semi-hack/trick to handle 'creinstall .' properly
554- [[ $user == % || ( -z $user && $plugin == . ) ]] && \
555- completions=( "${plugin}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|*.yml|*.yaml|*.py|*.ri|_zsh_highlight*|/zsdoc/*|*.ps1)(DN^/) ) || \
556- completions=( "${ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/_[^_.]*~*(*.zwc|*.html|*.txt|*.png|*.jpg|*.jpeg|*.js|*.md|*.yml|*.yaml|*.py|*.ri|_zsh_highlight*|/zsdoc/*|*.ps1)(DN^/) )
557- already_symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc (DN) )
558- backup_comps=( "${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN) )
559-
552+ nt () {
553+ [[ $(head -n 1 $REPLY) != *compdef* ]]
554+ }
555+ # Symlink any completion files included in the plugin directory
556+ [[ $user == % || ( -z $user && $plugin == . ) ]] && completions=( "${plugin}"/**/(_*|*zsh*)(DN^/+nt)) || completions=("${ ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/(_*|*.zsh*) (DN^/+nt))
557+ already_symlinked=( "${ZINIT[COMPLETIONS_DIR]}"/_ [^_.]*~*.zwc(DN))
558+ backup_comps=("${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN))
560559 # Symlink completions if they are not already there
561560 # either as completions (_fname) or as backups (fname)
562561 # OR - if its a reinstall
563562 for c in "${completions[@]:A}"; do
564- cfile="${c:t}"
565- bkpfile="${cfile#_}"
566- if [[ ( -z ${already_symlinked[(r)*/$cfile]} || $reinstall = 1 ) &&
567- -z ${backup_comps[(r)*/$bkpfile]}
568- ]]; then
563+ cfile="${c:t}"
564+ if [[ $cfile != (#s)_* ]]; then
565+ cfile="_${${$(head -n1 ${c})//\#compdef/}// /}"
566+ +zi-log "{m} _${${$(head -n1 ${c})//\#compdef/}// /}"
567+ fi
568+ bkpfile="${cfile#_}"
569+ if [[ ( -z ${already_symlinked[(r)*/$cfile]} || $reinstall = 1 ) && -z ${backup_comps[(r)*/$bkpfile]} ]]; then
569570 if [[ $reinstall = 1 ]]; then
570- # Remove old files
571571 command rm -f "${ZINIT[COMPLETIONS_DIR]}/$cfile" "${ZINIT[COMPLETIONS_DIR]}/$bkpfile"
572572 fi
573- INSTALLED_COMPS+=( $cfile )
573+ INSTALLED_COMPS+=($cfile)
574574 (( quiet )) || builtin print -Pr "Symlinking completion ${ZINIT[col-uname]}$cfile%f%b to completions directory."
575575 command ln -fs "$c" "${ZINIT[COMPLETIONS_DIR]}/$cfile"
576- # Make compinit notice the change
577576 .zinit-forget-completion "$cfile" "$quiet"
578577 else
579- SKIPPED_COMPS+=( $cfile )
578+ SKIPPED_COMPS+=($cfile)
580579 (( quiet )) || builtin print -Pr "Not symlinking completion \`${ZINIT[col-obj]}$cfile%f%b', it already exists."
581580 (( quiet )) || builtin print -Pr "${ZINIT[col-info2]}Use \`${ZINIT[col-pname]}zinit creinstall $abbrev_pspec${ZINIT[col-info2]}' to force install.%f%b"
582581 fi
583582 done
584-
585583 local comps msg
586- local -A comp_types=(\$INSTALLED_COMPS 'Installed' \$SKIPPED_COMPS 'Skipped re-installing')
584+ local -A comp_types=(\$INSTALLED_COMPS 'Installed' \$SKIPPED_COMPS 'Skipped re-installing')
587585 for comps msg in ${(kv)comp_types}; do
588- local comps_num=${#${(e)comps}}
586+ local comps_num=${#${(e)comps}}
589587 if (( comps_num > 0 )); then
590588 +zi-log "{m} ${msg} {num}$comps_num{rst} completion${=${comps_num:#1}:+s}"
591589 if (( quiet == 0 )); then
592590 +zi-log "{m} Added $comps_num completion${=${comps_num:#1}:+s} to {var}$comps{rst} array"
593591 fi
594592 fi
595593 done
596-
597- if (( ZSH_SUBSHELL )) {
598- builtin print -rl -- $INSTALLED_COMPS >! ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst
599- builtin print -rl -- $SKIPPED_COMPS >! ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst
600- }
601-
602- .zinit-compinit 1 1 &>/dev/null
594+ if (( ZSH_SUBSHELL )); then
595+ builtin print -rl -- $INSTALLED_COMPS >| ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst
596+ builtin print -rl -- $SKIPPED_COMPS >| ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst
597+ fi
598+ .zinit-compinit 1 1 &> /dev/null
603599} # ]]]
604600# FUNCTION: .zinit-compinit [[[
605601# User-exposed `compinit' frontend which first ensures that all
0 commit comments