Skip to content

Commit ee9adb7

Browse files
committed
feat: check for completion files
Signed-off-by: Vladislav Doster <[email protected]>
1 parent 22e66db commit ee9adb7

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
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/gh-r.zunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
HOME="$zi_test_dir" # Stops programs creating directories in user home
66
typeset -gx ZBIN="$zi_test_dir/polaris/bin" os_type="${OSTYPE//[0-9\.]*/}"
77
[[ ! -d $ZBIN ]] && mkdir -p "$ZBIN"
8-
zinit default-ice --quiet from'gh-r' lbin'!' null
8+
zinit default-ice --quiet from'gh-r' lbin'!'
99
}
1010

1111
@test 'act' { # Run your GitHub Actions locally

tests/ices.zunit

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,32 @@
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: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -528,78 +528,81 @@ 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
534534

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
539-
typeset -ga INSTALLED_COMPS SKIPPED_COMPS
540-
INSTALLED_COMPS=() SKIPPED_COMPS=()
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
540+
541+
typeset -gaU 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
551-
typeset -a completions already_symlinked backup_comps
550+
typeset -aU completions already_symlinked backup_comps
552551
local c cfile bkpfile
553-
# The plugin == . is a semi-hack/trick to handle 'creinstall .' properly
552+
nt () {
553+
[[ $(head -n 1 $REPLY) != *compdef* ]]
554+
}
555+
# Symlink any completion files included in the plugin directory
554556
[[ $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-
557+
completions=("${plugin}"/**/(_*|*.zsh*)(OLDN^/+nt)) || \
558+
completions=("${ZINIT[PLUGINS_DIR]}/${id_as//\//---}"/**/(_*|*.zsh*)(OLDN^/+nt))
559+
already_symlinked=("${ZINIT[COMPLETIONS_DIR]}"/_[^_.]*~*.zwc(DN))
560+
backup_comps=("${ZINIT[COMPLETIONS_DIR]}"/[^_.]*~*.zwc(DN))
560561
# Symlink completions if they are not already there
561562
# either as completions (_fname) or as backups (fname)
562563
# OR - if its a reinstall
563564
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
565+
local cfile="${c:t}"
566+
if [[ $cfile != (#s)_* ]]; then
567+
cfile="_${${$(head -n1 ${c})//\#compdef/}// /}"
568+
if (($completions[(Ie)$cfile])); then
569+
+zi-log "{m} ${cfile} is amongst the values of the array"
570+
continue
571+
else
572+
+zi-log "{m} Renaming completion {obj}${c:t}{rst} as {file}_${${$(head -n1 ${c})//\#compdef/}// /}{rst}"
573+
fi
574+
fi
575+
bkpfile="${cfile#_}"
576+
if [[ ( -z ${already_symlinked[(r)*/$cfile]} || $reinstall = 1 ) && -z ${backup_comps[(r)*/$bkpfile]} ]]; then
569577
if [[ $reinstall = 1 ]]; then
570-
# Remove old files
571578
command rm -f "${ZINIT[COMPLETIONS_DIR]}/$cfile" "${ZINIT[COMPLETIONS_DIR]}/$bkpfile"
572579
fi
573-
INSTALLED_COMPS+=( $cfile )
580+
INSTALLED_COMPS+=($cfile)
574581
(( quiet )) || builtin print -Pr "Symlinking completion ${ZINIT[col-uname]}$cfile%f%b to completions directory."
575582
command ln -fs "$c" "${ZINIT[COMPLETIONS_DIR]}/$cfile"
576-
# Make compinit notice the change
577583
.zinit-forget-completion "$cfile" "$quiet"
578584
else
579-
SKIPPED_COMPS+=( $cfile )
585+
SKIPPED_COMPS+=($cfile)
580586
(( quiet )) || builtin print -Pr "Not symlinking completion \`${ZINIT[col-obj]}$cfile%f%b', it already exists."
581587
(( quiet )) || builtin print -Pr "${ZINIT[col-info2]}Use \`${ZINIT[col-pname]}zinit creinstall $abbrev_pspec${ZINIT[col-info2]}' to force install.%f%b"
582588
fi
583589
done
584-
585590
local comps msg
586-
local -A comp_types=(\$INSTALLED_COMPS 'Installed' \$SKIPPED_COMPS 'Skipped re-installing')
591+
local -A comp_types=(\$INSTALLED_COMPS 'Installed' \$SKIPPED_COMPS 'Skipped re-installing')
587592
for comps msg in ${(kv)comp_types}; do
588-
local comps_num=${#${(e)comps}}
593+
local comps_num=${#${(e)comps}}
589594
if (( comps_num > 0 )); then
590595
+zi-log "{m} ${msg} {num}$comps_num{rst} completion${=${comps_num:#1}:+s}"
591596
if (( quiet == 0 )); then
592597
+zi-log "{m} Added $comps_num completion${=${comps_num:#1}:+s} to {var}$comps{rst} array"
593598
fi
594599
fi
595600
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
601+
if (( ZSH_SUBSHELL )); then
602+
builtin print -rl -- $INSTALLED_COMPS >| ${TMPDIR:-/tmp}/zinit.installed_comps.$$.lst
603+
builtin print -rl -- $SKIPPED_COMPS >| ${TMPDIR:-/tmp}/zinit.skipped_comps.$$.lst
604+
fi
605+
.zinit-compinit 1 1 &> /dev/null
603606
} # ]]]
604607
# FUNCTION: .zinit-compinit [[[
605608
# User-exposed `compinit' frontend which first ensures that all

0 commit comments

Comments
 (0)