[template] Use zrecompile and create digest file
for the autoloaded functions. According to the `zshbuiltins` documentation: Files containing multiple compiled functions are called `digest' files, and are intended to be used as elements of the FPATH/fpath special array. Compile all module init files, instead of some selected ones. This didn't impact performance much (time to run async block in zlogin when from 0.22s to 0.25s on my machine). Also refactor the zim `init.zsh` script, and do not unset `zmodules` anymore because we need it in zlogin. Didn't manage to make adding the prompt `prompt_*_setup` functions to the digest file work, so kept these separate. Fixes #86. Closes #218.
This commit is contained in:
parent
8aa086c481
commit
55df5a4755
2 changed files with 40 additions and 66 deletions
57
init.zsh
57
init.zsh
|
@ -9,44 +9,33 @@ if ! is-at-least 5.2; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define zim location
|
# Define zim location
|
||||||
(( ! ${+ZIM_HOME} )) && export ZIM_HOME="${ZDOTDIR:-${HOME}}/.zim"
|
(( ! ${+ZIM_HOME} )) && export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
|
||||||
|
|
||||||
# Source user configuration
|
# Source user configuration
|
||||||
if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then
|
[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc
|
||||||
source "${ZDOTDIR:-${HOME}}/.zimrc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
load_zim_module() {
|
# Autoload module functions
|
||||||
local wanted_module
|
() {
|
||||||
|
local mod_function
|
||||||
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||||
|
|
||||||
for wanted_module (${zmodules}); do
|
# autoload searches fpath for function locations; add enabled module function paths
|
||||||
if [[ -s "${ZIM_HOME}/modules/${wanted_module}/init.zsh" ]]; then
|
fpath=(${ZIM_HOME}/functions.zwc ${ZIM_HOME}/modules/prompt/functions ${fpath})
|
||||||
source "${ZIM_HOME}/modules/${wanted_module}/init.zsh"
|
|
||||||
elif [[ ! -d "${ZIM_HOME}/modules/${wanted_module}" ]]; then
|
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*)(-.N:t); do
|
||||||
print "No such module \"${wanted_module}\"." >&2
|
autoload -Uz ${mod_function}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize modules
|
||||||
|
() {
|
||||||
|
local zmodule
|
||||||
|
|
||||||
|
for zmodule (${zmodules}); do
|
||||||
|
if [[ -s ${ZIM_HOME}/modules/${zmodule}/init.zsh ]]; then
|
||||||
|
source ${ZIM_HOME}/modules/${zmodule}/init.zsh
|
||||||
|
elif [[ ! -d ${ZIM_HOME}/modules/${zmodule} ]]; then
|
||||||
|
print "No such module \"${zmodule}\"." >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
load_zim_function() {
|
|
||||||
local function_glob='^([_.]*|prompt_*_setup|README*)(-.N:t)'
|
|
||||||
local mod_function
|
|
||||||
|
|
||||||
# autoload searches fpath for function locations; add enabled module function paths
|
|
||||||
fpath=(${${zmodules}:+${ZIM_HOME}/modules/${^zmodules}/functions(/FN)} ${fpath})
|
|
||||||
|
|
||||||
function {
|
|
||||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
|
||||||
|
|
||||||
for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/${~function_glob}; do
|
|
||||||
autoload -Uz ${mod_function}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# initialize zim modules
|
|
||||||
load_zim_function
|
|
||||||
load_zim_module
|
|
||||||
|
|
||||||
unset zmodules
|
|
||||||
unfunction load_zim_{module,function}
|
|
||||||
|
|
|
@ -8,52 +8,37 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
(
|
(
|
||||||
# Function to determine the need of a zcompile. If the .zwc file
|
local file
|
||||||
# does not exist, or the base file is newer, we need to compile.
|
local zmodule
|
||||||
# These jobs are asynchronous, and will not impact the interactive shell
|
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||||
zcompare() {
|
autoload -U zrecompile
|
||||||
if [[ -s ${1} && ( ! -s ${1}.zwc || ${1} -nt ${1}.zwc ) ]]; then
|
|
||||||
zcompile ${1}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
local zim_mods=${ZIM_HOME}/modules
|
# zcompile the completion cache; siginificant speedup
|
||||||
setopt EXTENDED_GLOB
|
zrecompile -pq ${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump}
|
||||||
|
|
||||||
# zcompile the completion cache; siginificant speedup.
|
|
||||||
for file in ${ZDOTDIR:-${HOME}}/.zcomp^(*.zwc)(.); do
|
|
||||||
zcompare ${file}
|
|
||||||
done
|
|
||||||
|
|
||||||
# zcompile .zshrc
|
# zcompile .zshrc
|
||||||
zcompare ${ZDOTDIR:-${HOME}}/.zshrc
|
zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc
|
||||||
|
|
||||||
# zcompile some light module init scripts
|
# zcompile enabled module autoloaded functions
|
||||||
zcompare ${zim_mods}/git/init.zsh
|
zrecompile -pq ${ZIM_HOME}/functions ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc)(-.N)
|
||||||
zcompare ${zim_mods}/git-info/init.zsh
|
|
||||||
zcompare ${zim_mods}/utility/init.zsh
|
|
||||||
zcompare ${zim_mods}/pacman/init.zsh
|
|
||||||
zcompare ${zim_mods}/spectrum/init.zsh
|
|
||||||
zcompare ${zim_mods}/completion/init.zsh
|
|
||||||
zcompare ${zim_mods}/fasd/init.zsh
|
|
||||||
|
|
||||||
# zcompile all .zsh files in the custom module
|
# zcompile enabled module init scripts
|
||||||
for file in ${zim_mods}/custom/**/^(README.md|*.zwc)(.); do
|
for zmodule (${zmodules}); do
|
||||||
zcompare ${file}
|
zrecompile -pq ${ZIM_HOME}/modules/${zmodule}/init.zsh
|
||||||
done
|
done
|
||||||
|
|
||||||
# zcompile all autoloaded functions
|
# zcompile all prompt setup scripts
|
||||||
for file in ${zim_mods}/**/functions/^(*.zwc)(.); do
|
for file in ${ZIM_HOME}/modules/prompt/functions/prompt_*_setup; do
|
||||||
zcompare ${file}
|
zrecompile -pq ${file}
|
||||||
done
|
done
|
||||||
|
|
||||||
# syntax-highlighting
|
# syntax-highlighting
|
||||||
for file in ${zim_mods}/syntax-highlighting/external/highlighters/**^test-data/*.zsh; do
|
for file in ${ZIM_HOME}/modules/syntax-highlighting/external/highlighters/**^test-data/*.zsh; do
|
||||||
zcompare ${file}
|
zrecompile -pq ${file}
|
||||||
done
|
done
|
||||||
zcompare ${zim_mods}/syntax-highlighting/external/zsh-syntax-highlighting.zsh
|
zrecompile -pq ${ZIM_HOME}/modules/syntax-highlighting/external/zsh-syntax-highlighting.zsh
|
||||||
|
|
||||||
# zsh-histery-substring-search
|
# zsh-histery-substring-search
|
||||||
zcompare ${zim_mods}/history-substring-search/external/zsh-history-substring-search.zsh
|
zrecompile -pq ${ZIM_HOME}/modules/history-substring-search/external/zsh-history-substring-search.zsh
|
||||||
|
|
||||||
) &!
|
) &!
|
||||||
|
|
Loading…
Reference in a new issue