Add check-dumpfile action
that removes the dumpfile if it's outdated, so it will get dumped again when the shell starts next time. We're not using comdump because wrapped ZLE widgets cannot or should not be identified by compdump when they have a different name than the original one. See https://github.com/zsh-users/zsh-syntax-highlighting/issues/851
This commit is contained in:
parent
bd765df785
commit
35e1d2ea48
7 changed files with 87 additions and 30 deletions
|
@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
_No unreleased changes._
|
||||
### Added
|
||||
|
||||
- `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
|
||||
just checks if the number of completion functions and the Zsh version changed. The
|
||||
`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
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ _zimfw_build_init() {
|
|||
print -R "zmodule() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }"
|
||||
# Remove all prefixes from _zfpaths, _zfunctions and _zcmds
|
||||
local -r zpre=$'*\0'
|
||||
if (( ${#_zfpaths} )) print -R 'fpath=('${${_zfpaths#${~zpre}}:A}' ${fpath})'
|
||||
print -R 'typeset -g _zim_fpath=('${${_zfpaths#${~zpre}}:A}')'
|
||||
if (( ${#_zfpaths} )) print 'fpath=(${_zim_fpath} ${fpath})'
|
||||
if (( ${#_zfunctions} )) print -R 'autoload -Uz -- '${_zfunctions#${~zpre}}
|
||||
print -R ${(F)_zcmds#${~zpre}}
|
||||
) ${ztarget}
|
||||
|
|
22
src/stage2/50_zimfw_check_dumpfile.zsh.erb
Normal file
22
src/stage2/50_zimfw_check_dumpfile.zsh.erb
Normal file
|
@ -0,0 +1,22 @@
|
|||
_zimfw_check_dumpfile() {
|
||||
local -r ztarget=${ZIM_HOME}/.latest_comp zpre=$'*\0'
|
||||
local zdumpfile zline ckline=
|
||||
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 zcomp=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t))
|
||||
print -R ${(o)zcomp} >! ${ztarget} || return 1
|
||||
if [[ -e ${zdumpfile} ]]; then
|
||||
IFS=$' \t' read -rA zline < ${zdumpfile} || return 1
|
||||
if [[ ${zline[2]} -eq ${#zcomp} && ${zline[4]} == ${ZSH_VERSION} && \
|
||||
$(command cksum < ${ztarget} 2>/dev/null) == ${ckline} ]]; then
|
||||
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Already up to date"
|
||||
else
|
||||
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b."
|
||||
_zimfw_clean_dumpfile
|
||||
fi
|
||||
else
|
||||
_zimfw_print -PR "<%= okay %>%B${zdumpfile}:%b Not found"
|
||||
fi
|
||||
_zimfw_print 'Done with check-dumpfile.'
|
||||
}
|
|
@ -3,6 +3,6 @@ _zimfw_clean_compiled() {
|
|||
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
|
||||
local zopt
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) || return 1
|
||||
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
|
||||
_zimfw_print -P '<%= done %>Done with clean-compiled. Restart your terminal or run %Bzimfw compile%b to re-compile.'
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ _zimfw_clean_dumpfile() {
|
|||
local zdumpfile zopt
|
||||
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) || return 1
|
||||
_zimfw_print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) && \
|
||||
_zimfw_print -P "<%= done %>Done with clean-dumpfile.${_zrestartmsg}"
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ zimfw() {
|
|||
|
||||
Actions:
|
||||
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
||||
Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||
Also does %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to also see their output.
|
||||
%Bcheck-dumpfile%b Does %Bclean-dumpfile%b if new completion configuration needs to be dumped.
|
||||
%Bclean%b Clean all. Does both %Bclean-compiled%b and %Bclean-dumpfile%b.
|
||||
%Bclean-compiled%b Clean Zsh compiled files.
|
||||
%Bclean-dumpfile%b Clean completion dumpfile.
|
||||
|
@ -14,11 +15,11 @@ Actions:
|
|||
%Blist%b List all modules currently defined in %B<%= home %>/.zimrc%b.
|
||||
Use %B-v%b to also see the modules details.
|
||||
%Binit%b Same as %Binstall%b, but with output tailored to be used at terminal startup.
|
||||
%Binstall%b Install new modules. Also does %Bbuild%b and %Bcompile%b. Use %B-v%b to also see their
|
||||
output, and see skipped modules.
|
||||
%Binstall%b Install new modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to
|
||||
also see their output, and see skipped modules.
|
||||
%Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall.
|
||||
%Bupdate%b Update current modules. Also does %Bbuild%b and %Bcompile%b. Use %B-v%b to also see
|
||||
their output, and see skipped modules.
|
||||
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b
|
||||
to also see their output, and see skipped modules.
|
||||
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||
%Bversion%b Print zimfw version.
|
||||
|
||||
|
@ -50,8 +51,9 @@ Options:
|
|||
build)
|
||||
_zimfw_source_zimrc 2 && _zimfw_build || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_compile
|
||||
_zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
check-dumpfile) _zimfw_source_zimrc 2 && _zimfw_check_dumpfile ;;
|
||||
clean) _zimfw_source_zimrc 2 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
|
||||
clean-compiled) _zimfw_source_zimrc 2 && _zimfw_clean_compiled ;;
|
||||
clean-dumpfile) _zimfw_clean_dumpfile ;;
|
||||
|
@ -67,13 +69,13 @@ Options:
|
|||
_zimfw_install_update install || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_print -PR "<%= done %>Done with install.${_zrestartmsg}" # Only printed in verbose mode
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
install|update)
|
||||
_zimfw_install_update ${1} || return 1
|
||||
_zimfw_print -PR "<%= done %>Done with ${1}.${_zrestartmsg}"
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
uninstall) _zimfw_source_zimrc 2 && _zimfw_list_unuseds && _zimfw_uninstall ;;
|
||||
upgrade)
|
||||
|
|
52
zimfw.zsh
52
zimfw.zsh
|
@ -61,7 +61,8 @@ _zimfw_build_init() {
|
|||
print -R "zmodule() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }"
|
||||
# Remove all prefixes from _zfpaths, _zfunctions and _zcmds
|
||||
local -r zpre=$'*\0'
|
||||
if (( ${#_zfpaths} )) print -R 'fpath=('${${_zfpaths#${~zpre}}:A}' ${fpath})'
|
||||
print -R 'typeset -g _zim_fpath=('${${_zfpaths#${~zpre}}:A}')'
|
||||
if (( ${#_zfpaths} )) print 'fpath=(${_zim_fpath} ${fpath})'
|
||||
if (( ${#_zfunctions} )) print -R 'autoload -Uz -- '${_zfunctions#${~zpre}}
|
||||
print -R ${(F)_zcmds#${~zpre}}
|
||||
) ${ztarget}
|
||||
|
@ -321,12 +322,35 @@ _zimfw_version_check() {
|
|||
fi
|
||||
}
|
||||
|
||||
_zimfw_check_dumpfile() {
|
||||
local -r ztarget=${ZIM_HOME}/.latest_comp zpre=$'*\0'
|
||||
local zdumpfile zline ckline=
|
||||
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 zcomp=(${^zfpath}/^([^_]*|*~|*.zwc(|.old))(N:t))
|
||||
print -R ${(o)zcomp} >! ${ztarget} || return 1
|
||||
if [[ -e ${zdumpfile} ]]; then
|
||||
IFS=$' \t' read -rA zline < ${zdumpfile} || return 1
|
||||
if [[ ${zline[2]} -eq ${#zcomp} && ${zline[4]} == ${ZSH_VERSION} && \
|
||||
$(command cksum < ${ztarget} 2>/dev/null) == ${ckline} ]]; then
|
||||
_zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b Already up to date"
|
||||
else
|
||||
_zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b New completion configuration needs to be dumped. Will do %Bclean-dumpfile%b."
|
||||
_zimfw_clean_dumpfile
|
||||
fi
|
||||
else
|
||||
_zimfw_print -PR "%F{green})%f %B${zdumpfile}:%b Not found"
|
||||
fi
|
||||
_zimfw_print 'Done with check-dumpfile.'
|
||||
}
|
||||
|
||||
_zimfw_clean_compiled() {
|
||||
# Array with unique dirs. ${ZIM_HOME} or any subdirectory should only occur once.
|
||||
local -Ur zscriptdirs=(${ZIM_HOME} ${${_zdirs##${ZIM_HOME}/*}:A})
|
||||
local zopt
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) || return 1
|
||||
command rm -f ${zopt} ${^zscriptdirs}/**/*.zwc(|.old)(N) && \
|
||||
_zimfw_print -P 'Done with clean-compiled. Restart your terminal or run %Bzimfw compile%b to re-compile.'
|
||||
}
|
||||
|
||||
|
@ -334,8 +358,8 @@ _zimfw_clean_dumpfile() {
|
|||
local zdumpfile zopt
|
||||
zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump
|
||||
if (( _zprintlevel > 0 )) zopt=-v
|
||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) || return 1
|
||||
_zimfw_print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.'
|
||||
command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old))(N) && \
|
||||
_zimfw_print -P "Done with clean-dumpfile.${_zrestartmsg}"
|
||||
}
|
||||
|
||||
_zimfw_compile() {
|
||||
|
@ -352,7 +376,7 @@ _zimfw_compile() {
|
|||
}
|
||||
|
||||
_zimfw_info() {
|
||||
print -R 'zimfw version: '${_zversion}' (built at 2022-01-12 03:49:51 UTC, previous commit is 92bfa96)'
|
||||
print -R 'zimfw version: '${_zversion}' (built at 2022-01-18 19:51:41 UTC, previous commit is bd765df)'
|
||||
print -R 'ZIM_HOME: '${ZIM_HOME}
|
||||
print -R 'Zsh version: '${ZSH_VERSION}
|
||||
print -R 'System info: '$(command uname -a)
|
||||
|
@ -701,7 +725,8 @@ zimfw() {
|
|||
|
||||
Actions:
|
||||
%Bbuild%b Build %B${ZIM_HOME}/init.zsh%b and %B${ZIM_HOME}/login_init.zsh%b.
|
||||
Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||
Also does %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to also see their output.
|
||||
%Bcheck-dumpfile%b Does %Bclean-dumpfile%b if new completion configuration needs to be dumped.
|
||||
%Bclean%b Clean all. Does both %Bclean-compiled%b and %Bclean-dumpfile%b.
|
||||
%Bclean-compiled%b Clean Zsh compiled files.
|
||||
%Bclean-dumpfile%b Clean completion dumpfile.
|
||||
|
@ -711,11 +736,11 @@ Actions:
|
|||
%Blist%b List all modules currently defined in %B${ZDOTDIR:-${HOME}}/.zimrc%b.
|
||||
Use %B-v%b to also see the modules details.
|
||||
%Binit%b Same as %Binstall%b, but with output tailored to be used at terminal startup.
|
||||
%Binstall%b Install new modules. Also does %Bbuild%b and %Bcompile%b. Use %B-v%b to also see their
|
||||
output, and see skipped modules.
|
||||
%Binstall%b Install new modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b to
|
||||
also see their output, and see skipped modules.
|
||||
%Buninstall%b Delete unused modules. Prompts for confirmation. Use %B-q%b for quiet uninstall.
|
||||
%Bupdate%b Update current modules. Also does %Bbuild%b and %Bcompile%b. Use %B-v%b to also see
|
||||
their output, and see skipped modules.
|
||||
%Bupdate%b Update current modules. Also does %Bbuild%b, %Bcheck-dumpfile%b and %Bcompile%b. Use %B-v%b
|
||||
to also see their output, and see skipped modules.
|
||||
%Bupgrade%b Upgrade zimfw. Also does %Bcompile%b. Use %B-v%b to also see its output.
|
||||
%Bversion%b Print zimfw version.
|
||||
|
||||
|
@ -747,8 +772,9 @@ Options:
|
|||
build)
|
||||
_zimfw_source_zimrc 2 && _zimfw_build || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_compile
|
||||
_zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
check-dumpfile) _zimfw_source_zimrc 2 && _zimfw_check_dumpfile ;;
|
||||
clean) _zimfw_source_zimrc 2 && _zimfw_clean_compiled && _zimfw_clean_dumpfile ;;
|
||||
clean-compiled) _zimfw_source_zimrc 2 && _zimfw_clean_compiled ;;
|
||||
clean-dumpfile) _zimfw_clean_dumpfile ;;
|
||||
|
@ -764,13 +790,13 @@ Options:
|
|||
_zimfw_install_update install || return 1
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_print -PR "Done with install.${_zrestartmsg}" # Only printed in verbose mode
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
install|update)
|
||||
_zimfw_install_update ${1} || return 1
|
||||
_zimfw_print -PR "Done with ${1}.${_zrestartmsg}"
|
||||
(( _zprintlevel-- ))
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_compile
|
||||
_zimfw_source_zimrc 2 && _zimfw_build && _zimfw_check_dumpfile && _zimfw_compile
|
||||
;;
|
||||
uninstall) _zimfw_source_zimrc 2 && _zimfw_list_unuseds && _zimfw_uninstall ;;
|
||||
upgrade)
|
||||
|
|
Loading…
Reference in a new issue