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.plugin.zsh" ]]; then
32 fname="$dname/$plugin.plugin.zsh"
33 elif [[ -r "$dname/init.zsh" ]]; then
36 fname="$dname/init.zsh"
40 if [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
41 # Add plugin function path when folder exists
42 axzsh_fpath+=("$dname/functions")
45 if [[ -r "$fname" ]]; then
46 [[ -n "$AXZSH_DEBUG" ]] \
47 && echo " - $plugin ($type) ..."
51 # It is a success, even if only the plugin directory (and no script!)
52 # exists at all! Rationale: The script could be of an other type ...
56 # Make sure that "AXZSH" variable is set and exported
57 if [[ -z "$AXZSH" ]]; then
58 export AXZSH="$HOME/.axzsh"
59 if [[ -f "$HOME/.axzsh.debug" ]]; then
62 echo "AXZSH_DEBUG=$AXZSH_DEBUG"
63 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
67 [[ -n "$AXZSH_DEBUG" ]] && echo "ยป $script_name:"
69 # Setup list of plugins to load:
70 typeset -U plugin_list
73 "$AXZSH/active_plugins/"*(N)
77 # Read in all the plugins for the current "type":
78 for plugin ($plugin_list); do
79 axzsh_load_plugin "$plugin" "$script_type"
81 unfunction axzsh_load_plugin
82 unset script_name script_type plugin