From 18696c67b31aba8aa794261ff1e5b287cd7fa625 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 27 Sep 2017 07:24:51 -0500 Subject: [PATCH] [template] zcompile only enabled modules and don't zcompile the `.zcompdump` file in zlogin, since it's already being compiled by the completion module. We've been trying to zcompile it twice before this change. Also refactor the zim `init.zsh` script, and do not unset `zmodules` anymore because we need it in zlogin. --- init.zsh | 49 +++++++++++++++++++----------------------------- templates/zlogin | 30 +++++++++++++---------------- 2 files changed, 32 insertions(+), 47 deletions(-) diff --git a/init.zsh b/init.zsh index c49782d..43f7721 100755 --- a/init.zsh +++ b/init.zsh @@ -9,44 +9,33 @@ if ! is-at-least 5.2; then fi # Define zim location -(( ! ${+ZIM_HOME} )) && export ZIM_HOME="${ZDOTDIR:-${HOME}}/.zim" +(( ! ${+ZIM_HOME} )) && export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim # Source user configuration -if [[ -s "${ZDOTDIR:-${HOME}}/.zimrc" ]]; then - source "${ZDOTDIR:-${HOME}}/.zimrc" -fi +[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc -load_zim_module() { - local wanted_module - - for wanted_module (${zmodules}); do - if [[ -s "${ZIM_HOME}/modules/${wanted_module}/init.zsh" ]]; then - source "${ZIM_HOME}/modules/${wanted_module}/init.zsh" - elif [[ ! -d "${ZIM_HOME}/modules/${wanted_module}" ]]; then - print "No such module \"${wanted_module}\"." >&2 - fi - done -} - -load_zim_function() { - local function_glob='^([_.]*|prompt_*_setup|README*)(-.N:t)' +# Autoload module functions +() { local mod_function + setopt LOCAL_OPTIONS EXTENDED_GLOB # autoload searches fpath for function locations; add enabled module function paths fpath=(${ZIM_HOME}/functions.zwc ${ZIM_HOME}/modules/prompt/functions ${fpath}) - function { - setopt LOCAL_OPTIONS EXTENDED_GLOB - - for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/${~function_glob}; do - autoload -Uz ${mod_function} - done - } + for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*)(-.N:t); do + autoload -Uz ${mod_function} + done } -# initialize zim modules -load_zim_function -load_zim_module +# Initialize modules +() { + local zmodule -unset zmodules -unfunction load_zim_{module,function} + 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 + done +} diff --git a/templates/zlogin b/templates/zlogin index 714941e..a958d82 100644 --- a/templates/zlogin +++ b/templates/zlogin @@ -8,38 +8,34 @@ # ( - local zim_mods=${ZIM_HOME}/modules - setopt EXTENDED_GLOB + local file + local zmodule + setopt LOCAL_OPTIONS EXTENDED_GLOB autoload -U zrecompile - # zcompile the completion cache; siginificant speedup. - for file in ${ZDOTDIR:-${HOME}}/.zcomp^(*.zwc)(.); do - zrecompile -pq ${file} - done - # zcompile .zshrc zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc - # zcompile all module init scripts - for file in ${zim_mods}/*/init.zsh; do - zrecompile -pq ${file} + # zcompile enabled module autoloaded functions + zrecompile -pq ${ZIM_HOME}/functions ${ZIM_HOME}/modules/${^zmodules}/functions/^([_.]*|prompt_*_setup|README*|*.zwc)(-.N) + + # zcompile enabled module init scripts + for zmodule (${zmodules}); do + zrecompile -pq ${ZIM_HOME}/modules/${zmodule}/init.zsh done - # zcompile all autoloaded functions - zrecompile -pq ${ZIM_HOME}/functions ${zim_mods}/*/functions/^([_.]*|prompt_*_setup|README*|*.zwc)(.) - # zcompile all prompt setup scripts - for file in ${zim_mods}/prompt/functions/prompt_*_setup; do + for file in ${ZIM_HOME}/modules/prompt/functions/prompt_*_setup; do zrecompile -pq ${file} done # 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 zrecompile -pq ${file} done - zrecompile -pq ${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 - zrecompile -pq ${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 ) &!