# - $1: Script name
# - $2: Stage name (ax-io, zprofile, zshrc, zlogin, zlogout)
function axzsh_handle_stage {
- name="$1"
- type="$2"
+ local name="$1"
+ local type="$2"
[[ -n "$AXZSH_DEBUG" ]] && echo "ยป $name ($type):"
# Enable instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts,
# [y/n] confirmations, etc.) must be executed before this, so all ax-zsh
- # plugings should do output in their "zprofile" stage!
+ # plugings should do output in their "ax-io" stage only!
if [[ "$type" == "zprofile" ]]; then
p10k_instant_prompt="${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
[[ -r "$p10k_instant_prompt" ]] && source "$p10k_instant_prompt"
fi
# Initialize cache
- mkdir -p "$AXZSH/cache"
- cache_file="$AXZSH/cache/$type.cache"
+ [[ -d "$AXZSH/cache" ]] || mkdir -p "$AXZSH/cache"
+ local cache_file="$AXZSH/cache/$type.cache"
- cat_cmd=${commands[cat]:-cat}
+ local cat_cmd=${commands[cat]:-cat}
if [[ -r "$cache_file" ]]; then
# Cache file exists, use it!
[[ -n "$AXZSH_DEBUG" ]] \
&& echo " - Reading cache file \"$cache_file\" ..."
source "$cache_file"
- unfunction ax_plugin_init
+ unfunction axzsh_plugin_init
else
# No cache file available.
+ local new_cache_file="$cache_file.NEW"
+
# Setup list of plugins to load:
+ local plugin_list
typeset -U plugin_list
plugin_list=(
- "$AXZSH/core/"[0-5]*
+ "$AXZSH/core/"[0-4]*
"$AXZSH/active_plugins/"*(N)
- "$AXZSH/core/"[6-9]*
+ "$AXZSH/core/"[5-9]*
)
# Create new cache file:
- if [[ -n "$cache_file" ]]; then
- [[ -n "$AXZSH_DEBUG" ]] \
- && echo " (Writing new cache file to \"$cache_file\" ...)"
- printf "# %s\n\n" "$(LC_ALL=C date)" >"$cache_file"
+ [[ -n "$AXZSH_DEBUG" ]] \
+ && echo " (Writing new cache file to \"$new_cache_file\" ...)"
+ if ! printf "# %s\n\n" "$(LC_ALL=C date)" >"$new_cache_file"; then
+ unset new_cache_file
+ else
+ # New cache file successfully created ...
+ if [[ "$type" = "ax-io" ]]; then
+ # AX-IO Stage:
+ # Write an initial PATH variable to the cache
+ # file, which becomes overwritten by the path
+ # plugin at the "zprofile" stage later on, but
+ # this way "ax-io" stage plugins have a somewhat
+ # saner PATH to begin with ...
+ printf 'export PATH="%s"\n\n' "$PATH" >>"$new_cache_file"
+ fi
fi
# Read in all the plugins for the current "type":
if [[ "$plugin:t" == "99_cleanup" && "$type" = "zshrc" ]]; then
if [[ -r "$AXZSH_THEME" ]]; then
source "$AXZSH_THEME"
- if [[ -n "$cache_file" ]]; then
+ if [[ -n "$new_cache_file" ]]; then
# Source the theme in the new cache file:
- echo "# BEGIN Theme" >>"$cache_file"
- echo 'source "$AXZSH_THEME"' >>"$cache_file"
- echo "# END Theme" >>"$cache_file"
+ echo "# BEGIN Theme" >>"$new_cache_file"
+ echo 'source "$AXZSH_THEME"' >>"$new_cache_file"
+ echo "# END Theme" >>"$new_cache_file"
fi
fi
fi
- axzsh_load_plugin "$plugin" "$type" "$cache_file"
+ axzsh_load_plugin "$plugin" "$type" "$new_cache_file"
done
+
+ if [[ -n "$cache_file" && -n "$new_cache_file" && -r "$new_cache_file" ]]; then
+ # Move newly created cache file in place:
+ mv "$new_cache_file" "$cache_file"
+ fi
fi
}
# Oh My ZSH plugin with "zsh-" prefix stripped
type="plugin.zsh"
fname="$dname/${plugin_short##zsh-}.plugin.zsh"
+ elif [[ -r "$dname/${plugin%.plugin.zsh}.plugin.zsh" ]]; then
+ # Oh My ZSH plugin with ".plugin.zsh" suffix in its name
+ type="plugin.zsh"
+ fname="$dname/${plugin}"
elif [[ -r "$dname/init.zsh" ]]; then
# Prezto module
type="init.zsh"
if [[ -n "$cache_file" ]]; then
# Add plugin data to cache
- printf "# BEGIN: %s\nax_plugin_init()\n{\n" "$fname" >>"$cache_file"
+ printf "# BEGIN: %s\naxzsh_plugin_init()\n{\n" "$fname" >>"$cache_file"
case "$fname" in
*"/repos/"*)
echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type): \"$fname\" ...'" >>$cache_file
echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type, cached) ...'" >>$cache_file
"$cat_cmd" "$fname" >>"$cache_file"
esac
- printf "}\nax_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file"
+ printf "}\naxzsh_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file"
fi
fi
# Check for "debug mode" ...
if [[ -f "$AXZSH/debug" || -f "$HOME/.axzsh.debug" ]]; then
export AXZSH_DEBUG=1
+ export POWERLEVEL9K_INSTANT_PROMPT=quiet
echo "AXZSH=$AXZSH"
echo "AXZSH_DEBUG=$AXZSH_DEBUG"
echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"