1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015 Alexander Barton <alex@barton.de>
4 # Load plugin code of a given type.
6 # - $2: plugin type (optional; defaults to "zshrc")
7 function axzsh_load_plugin {
9 [[ -z "$2" ]] && type="zshrc" || type="$2"
12 "$AXZSH_PLUGIN_D/$plugin" \
13 "$AXZSH/plugins/$plugin" \
14 "$AXZSH/core/$plugin" \
16 [[ ! -d "$dname" ]] && continue
18 fname="$dname/$plugin.$type"
19 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
20 if [[ -r "$dname/$plugin.plugin.zsh" ]]; then
23 fname="$dname/$plugin.plugin.zsh"
24 elif [[ -r "$dname/init.zsh" ]]; then
27 fname="$dname/init.zsh"
31 if [[ -r "$fname" ]]; then
32 [[ -f "$HOME/.axzsh.debug" ]] \
33 && echo " - $plugin ($type) ..."
40 if [[ -f "$HOME/.axzsh.debug" ]]; then
41 # Show error message for all stages in "debug mode":
42 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
43 elif [[ "$type" == "zshrc" ]]; then
44 # Show error message for the "zshrc" stage:
45 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
50 # Make sure that "AXZSH" variable is set and exported
51 if [[ -z "$AXZSH" ]]; then
52 export AXZSH="$HOME/.axzsh"
53 [[ -f "$HOME/.axzsh.debug" ]] && echo "AXZSH=$AXZSH"
56 # Setup list of default plugins if not set already. This allows users to
57 # overwrite this list in their "~/.zshenv" file, for example.
58 typeset -U axzsh_default_plugins
59 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
60 axzsh_default_plugins=(
73 # Setup list of plugins to load:
74 typeset -U plugin_list
77 $axzsh_default_plugins
83 # Read in all the plugins for the current "type":
84 script_name="$(basename -- "${(%):-%N}")"
85 script_type="$script_name[2,-1]"
86 [[ -f "$HOME/.axzsh.debug" ]] && echo "ยป $script_name:"
87 for plugin ($plugin_list); do
88 axzsh_load_plugin "$(basename "$plugin")" "$script_type"
90 unset script_name script_type plugin