Skip to content

Commit 8e65a67

Browse files
committed
feat: check for completion files
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
1 parent 22e66db commit 8e65a67

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

.github/workflows/tests.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,22 @@ jobs:
6767
mkdir -p "$HOME/.local/bin" && echo "$HOME/.local/bin" >> $GITHUB_PATH
6868
git clone --depth 1 https://github.com/zdharma-continuum/zunit; cd ./zunit
6969
zsh -l -c './build.zsh' && sudo chmod u+x ./zunit && cp ./zunit "$HOME/.local/bin/"
70-
71-
- name: "gh-r"
72-
shell: zsh {0}
73-
run: $HOME/.local/bin/zunit run --verbose tests/gh-r.zunit
74-
70+
7571
- name: "annexes"
7672
run: zunit run tests/annexes.zunit
77-
73+
7874
- name: "commands"
7975
run: zunit run tests/commands.zunit
80-
76+
8177
- name: "gh-r"
8278
run: zunit run tests/gh-r.zunit
83-
79+
8480
- name: "ices"
8581
run: zunit run tests/ices.zunit
86-
82+
8783
- name: "plugins"
8884
run: zunit run tests/plugins.zunit
89-
85+
9086
- name: "snippets"
9187
run: zunit run tests/snippets.zunit
9288

tests/ices.zunit

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,37 @@
3434
assert "$ZPLUGINS/test---atclone/readme.md" not_exists
3535
}
3636
@test 'make' {
37-
run zinit as"null" id-as"test/make" atclone"printf 'all:\n\ttouch whatever\n' > Makefile" make"all" for zdharma-continuum/null
37+
run zinit as"null" id-as"test/make" atclone"printf 'all:\n\ttouch whatever\n' > Makefile" make"" for zdharma-continuum/null
3838
assert $state equals 0
3939
assert "$ZPLUGINS/test---make/whatever" is_file
4040
}
4141
@test 'completions' {
42-
run zinit as"null" id-as"test/completions" atclone"touch _whatever" completions for zdharma-continuum/null
42+
run zinit as"null" id-as"test/completions" atclone"echo '#compdef whatever' >| _whatever" completions for zdharma-continuum/null
4343
assert $state equals 0
4444
assert "$ZPLUGINS/test---completions/_whatever" is_file
4545
assert "$ZINIT[COMPLETIONS_DIR]/_whatever" is_file
46+
run zinit completions
4647
}
4748
@test 'completions-overwrite' {
4849
# if both are given, the completions wins
49-
run zinit as"null" id-as"test/completions-overwrite" atclone"touch _whatever2" nocompletions completions for zdharma-continuum/null
50+
run zinit as"null" id-as"test/completions-overwrite" atclone"echo '#compdef whatever2' >| _whatever2" nocompletions completions for zdharma-continuum/null
5051
assert $state equals 0
5152
assert "$ZPLUGINS/test---completions-overwrite/_whatever2" is_file
5253
assert "$ZINIT[COMPLETIONS_DIR]/_whatever2" is_file
54+
run zinit completions
5355
}
5456
@test 'completions-ignored' {
5557
# only the _valid file should be installed as a completion
56-
run zinit as"null" id-as"test/ignored_completions" atclone"touch __init__.py _valid" completions for zdharma-continuum/null
58+
run zinit as"null" id-as"test/ignored_completions" atclone"touch __init__.py; echo '#compdef valid' >| _valid" completions for zdharma-continuum/null
5759
assert $state equals 0
5860
assert "$ZPLUGINS/test---ignored_completions/_valid" is_file
5961
assert "$ZPLUGINS/test---ignored_completions/__init__.py" is_file
6062
assert "$ZINIT[COMPLETIONS_DIR]/_valid" is_file
6163
COMPS=( "$ZINIT[COMPLETIONS_DIR]"/_* )
6264
assert __init__.py is_not_value_in $COMPS
65+
zinit delete --yes test/ignored_completions
66+
run zinit cuninstall test/ignored_completions
67+
assert $output contains 'No completions found for `test/ignored_completions'
6368
}
6469

6570
# vim:ft=zsh:sw=2:sts=2:et:foldmarker=\ {,}:foldmethod=marker

zinit-install.zsh

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)