From d1529bb40528aafd9bdb98ba5a03d4ecb79d82bb Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Fri, 7 Apr 2017 21:42:49 +0200 Subject: [PATCH] Cache: Read "zprofile" in the correct context in "zshrc" stage When in the "zshrc" stage, make sure that the "zprofile" stage has already been handled. This uses the "01_zprofile" plugin which is used in the "zshrc.cache" file itself as well, but can't be used successfully there because it becomes sourced inside of a ZSH function; so we have to source it in the global context manually ... And use the cache "zprofile.cache" in the "01_zprofile" plugin, when available. --- ax.zsh | 7 +++++++ core/01_zprofile/01_zprofile.zshrc | 27 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ax.zsh b/ax.zsh index 556061a..a841af5 100644 --- a/ax.zsh +++ b/ax.zsh @@ -116,6 +116,13 @@ cat_cmd=${commands[cat]:-cat} if [[ -r "$cache_file" ]]; then # Cache file exists, use it! + # But when in the "zshrc" stage, make sure that the "zprofile" stage + # has already been handled (this uses the "01_zprofile" plugin which + # is used in the "zshrc.cache" as well, but can't be used successfully + # there because it becomes sourced inside of a ZSH function; so we have + # to source it here in the global context manually ...): + [[ -z "$AXZSH_ZPROFILE_READ" && "$script_type" = "zshrc" ]] \ + && source "$AXZSH/core/01_zprofile/01_zprofile.zshrc" [[ -n "$AXZSH_DEBUG" ]] \ && echo " - Reading cache file \"$cache_file\" ..." source "$cache_file" diff --git a/core/01_zprofile/01_zprofile.zshrc b/core/01_zprofile/01_zprofile.zshrc index 732318d..93a423d 100644 --- a/core/01_zprofile/01_zprofile.zshrc +++ b/core/01_zprofile/01_zprofile.zshrc @@ -10,8 +10,29 @@ unset PS1 [[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zsh:" -for plugin ($plugin_list); do - axzsh_load_plugin "$plugin" "zprofile" -done + +if [[ -r "$AXZSH/cache/zprofile.cache" ]]; then + # Cache file exists, use it! + [[ -n "$AXZSH_DEBUG" ]] \ + && echo " - Reading cache file \"$AXZSH/cache/zprofile.cache\" ..." + source "$AXZSH/cache/zprofile.cache" +else + # No cache file, so read plugins manually. The "plugin_list" can be + # empty, when the "zshrc" stage has been read in using the cache file, + # but there is no cache file for the "zprofile" stage. In that case + # the "plugin_list" must be assembled right now (see "ax.zsh" file!): + if [[ -z "$plugin_list" ]]; then + typeset -U plugin_list + plugin_list=( + "$AXZSH/core/"[0-5]* + "$AXZSH/active_plugins/"*(N) + "$AXZSH/core/"[6-9]* + ) + fi + for plugin ($plugin_list); do + axzsh_load_plugin "$plugin" "zprofile" + done +fi AXZSH_ZPROFILE_READ=2 + [[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zsh (end)" -- 2.39.2