Simplify check-dumpfile to do the same as compinit

first because simpler is usually better, and second because we cannot
always guarantee that the .latest_comp file, which was holding the list
of all completion functions, is consistently in sync with the dumpfile
that is generated afterwards.
This commit is contained in:
Eric Nielsen 2022-01-18 20:51:11 -05:00
parent 35e1d2ea48
commit ac2843d8c8
No known key found for this signature in database
GPG Key ID: 47D1DBFA0765A1FB
3 changed files with 13 additions and 21 deletions

View File

@ -10,10 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- `check-dumpfile` action. It runs in the build, install and update actions, and checks if a - `check-dumpfile` action. It runs in the build, install and update actions, and checks if a
new completion configuration needs to be dumped. It's more powerful than `compinit`, which new completion configuration needs to be dumped. It's intended to be used with `compinit -C`,
just checks if the number of completion functions and the Zsh version changed. The so no checks are done during the shell startup.
`check-dumpfile` action also checks if the actual list of completion functions changed. It's
intended to be used with `compinit -C`, so no checks are done during the shell startup.
## [1.7.0] - 2022-01-12 ## [1.7.0] - 2022-01-12

View File

@ -1,15 +1,12 @@
_zimfw_check_dumpfile() { _zimfw_check_dumpfile() {
local -r ztarget=${ZIM_HOME}/.latest_comp zpre=$'*\0' local zdumpfile zline
local zdumpfile zline ckline= local -r zpre=$'*\0'
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if [[ -r ${ztarget} ]] ckline=$(command cksum < ${ztarget} 2>/dev/null)
local -r zfpath=(${${_zfpaths#${~zpre}}:A} ${fpath:|_zim_fpath}) local -r zfpath=(${${_zfpaths#${~zpre}}:A} ${fpath:|_zim_fpath})
local -r zcomp=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t)) local -r zcomps=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t))
print -R ${(o)zcomp} >! ${ztarget} || return 1 zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
if [[ -e ${zdumpfile} ]]; then if [[ -e ${zdumpfile} ]]; then
IFS=$' \t' read -rA zline < ${zdumpfile} || return 1 IFS=$' \t' read -rA zline < ${zdumpfile} || return 1
if [[ ${zline[2]} -eq ${#zcomp} && ${zline[4]} == ${ZSH_VERSION} && \ if [[ ${zline[2]} -eq ${#zcomps} && ${zline[4]} == ${ZSH_VERSION} ]]; then
$(command cksum < ${ztarget} 2>/dev/null) == ${ckline} ]]; then
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Already up to date" _zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Already up to date"
else else
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b." _zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b."

View File

@ -323,17 +323,14 @@ _zimfw_version_check() {
} }
_zimfw_check_dumpfile() { _zimfw_check_dumpfile() {
local -r ztarget=${ZIM_HOME}/.latest_comp zpre=$'*\0' local zdumpfile zline
local zdumpfile zline ckline= local -r zpre=$'*\0'
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
if [[ -r ${ztarget} ]] ckline=$(command cksum < ${ztarget} 2>/dev/null)
local -r zfpath=(${${_zfpaths#${~zpre}}:A} ${fpath:|_zim_fpath}) local -r zfpath=(${${_zfpaths#${~zpre}}:A} ${fpath:|_zim_fpath})
local -r zcomp=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t)) local -r zcomps=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t))
print -R ${(o)zcomp} >! ${ztarget} || return 1 zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
if [[ -e ${zdumpfile} ]]; then if [[ -e ${zdumpfile} ]]; then
IFS=$' \t' read -rA zline < ${zdumpfile} || return 1 IFS=$' \t' read -rA zline < ${zdumpfile} || return 1
if [[ ${zline[2]} -eq ${#zcomp} && ${zline[4]} == ${ZSH_VERSION} && \ if [[ ${zline[2]} -eq ${#zcomps} && ${zline[4]} == ${ZSH_VERSION} ]]; then
$(command cksum < ${ztarget} 2>/dev/null) == ${ckline} ]]; then
_zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b Already up to date" _zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b Already up to date"
else else
_zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b." _zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b."
@ -376,7 +373,7 @@ _zimfw_compile() {
} }
_zimfw_info() { _zimfw_info() {
print -R 'zimfw version: '${_zversion}' (built at 2022-01-18 19:51:41 UTC, previous commit is bd765df)' print -R 'zimfw version: '${_zversion}' (built at 2022-01-19 01:49:13 UTC, previous commit is 35e1d2e)'
print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'ZIM_HOME: '${ZIM_HOME}
print -R 'Zsh version: '${ZSH_VERSION} print -R 'Zsh version: '${ZSH_VERSION}
print -R 'System info: '$(command uname -a) print -R 'System info: '$(command uname -a)