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 if [[ ! -d "$dname" ]]; then
18 if [[ -n "$AXZSH_DEBUG" ]]; then
19 # Show error message for all stages in "debug mode":
20 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
21 elif [[ "$type" == "zshrc" ]]; then
22 # Show error message for the "zshrc" stage:
23 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
28 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
29 if [[ -r "$dname/$plugin.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
30 # Native AX-ZSH plugin, but for different stage. Skip it!
32 elif [[ -r "$dname/$plugin.plugin.zsh" ]]; then
35 fname="$dname/$plugin.plugin.zsh"
36 elif [[ -r "$dname/init.zsh" ]]; then
39 fname="$dname/init.zsh"
41 echo "AX-ZSH plugin type of \"$plugin\" unknown, skipped!" >&2
45 if [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
46 # Add plugin function path when folder exists
47 axzsh_fpath+=("$dname/functions")
50 if [[ -r "$fname" ]]; then
51 [[ -n "$AXZSH_DEBUG" ]] \
52 && echo " - $plugin ($type) ..."
56 # It is a success, even if only the plugin directory (and no script!)
57 # exists at all! Rationale: The script could be of an other type ...
61 # Make sure that "AXZSH" variable is set and exported
62 if [[ -z "$AXZSH" ]]; then
63 export AXZSH="$HOME/.axzsh"
64 if [[ -f "$HOME/.axzsh.debug" ]]; then
67 echo "AXZSH_DEBUG=$AXZSH_DEBUG"
68 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
72 [[ -n "$AXZSH_DEBUG" ]] && echo "ยป $script_name:"
74 # Setup list of plugins to load:
75 typeset -U plugin_list
78 "$AXZSH/active_plugins/"*(N)
82 # Read in all the plugins for the current "type":
83 for plugin ($plugin_list); do
84 axzsh_load_plugin "$plugin" "$script_type"
86 unfunction axzsh_load_plugin
87 unset script_name script_type plugin