1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015-2016 Alexander Barton <alex@barton.de>
4 script_name="${${(%):-%N}:t}"
5 script_type="$script_name[2,-1]"
7 # Load plugin code of a given type.
9 # - $2: plugin type (optional; defaults to "zshrc")
10 function axzsh_load_plugin {
13 [[ -z "$2" ]] && type="zshrc" || type="$2"
14 fname="$dname/$plugin.$type"
16 [[ "$plugin" =~ "#" ]] && plugin=$(echo $plugin | cut -d'#' -f2-)
18 plugin_short=${plugin%.zsh}
20 if [[ ! -d "$dname" ]]; then
22 if [[ -n "$AXZSH_DEBUG" ]]; then
23 # Show error message for all stages in "debug mode":
24 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
25 elif [[ "$type" == "zshrc" ]]; then
26 # Show error message for the "zshrc" stage:
27 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
32 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
33 if [[ -r "$dname/$plugin.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
34 # Native AX-ZSH plugin, but for different stage. Skip it!
36 elif [[ -r "$dname/${plugin_short}.plugin.zsh" ]]; then
39 fname="$dname/${plugin_short}.plugin.zsh"
40 elif [[ -r "$dname/init.zsh" ]]; then
43 fname="$dname/init.zsh"
45 echo "AX-ZSH plugin type of \"$plugin\" unknown, skipped!" >&2
49 if [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
50 # Add plugin function path when folder exists
51 axzsh_fpath+=("$dname/functions")
54 if [[ -r "$fname" ]]; then
55 [[ -n "$AXZSH_DEBUG" ]] \
56 && echo " - $plugin ($type) ..."
60 # It is a success, even if only the plugin directory (and no script!)
61 # exists at all! Rationale: The script could be of an other type ...
65 # Make sure that "AXZSH" variable is set and exported
66 if [[ -z "$AXZSH" ]]; then
67 export AXZSH="$HOME/.axzsh"
68 if [[ -f "$HOME/.axzsh.debug" ]]; then
71 echo "AXZSH_DEBUG=$AXZSH_DEBUG"
72 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
76 [[ -n "$AXZSH_DEBUG" ]] && echo "ยป $script_name:"
78 # Setup list of plugins to load:
79 typeset -U plugin_list
82 "$AXZSH/active_plugins/"*(N)
86 # Read in all the plugins for the current "type":
87 for plugin ($plugin_list); do
88 axzsh_load_plugin "$plugin" "$script_type"
90 unfunction axzsh_load_plugin
91 unset script_name script_type plugin