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) ..."
39 [[ -f "$HOME/.axzsh.debug" ]] \
40 && echo "Plugin \"$plugin\" not found (type \"$type\")!" >/dev/stderr
44 # Make sure that "AXZSH" variable is set and exported
45 if [[ -z "$AXZSH" ]]; then
46 export AXZSH="$HOME/.axzsh"
47 [[ -f "$HOME/.axzsh.debug" ]] && echo "AXZSH=$AXZSH"
50 # Setup list of default plugins if not set already. This allows users to
51 # overwrite this list in their "~/.zshrnv" file, for example.
52 typeset -U axzsh_default_plugins
53 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
54 axzsh_default_plugins=(
68 # Setup list of plugins to load:
69 typeset -U plugin_list
72 $axzsh_default_plugins
78 # Read in all the plugins for the current "type":
79 script_name="$(basename -- "${(%):-%N}")"
80 script_type="$script_name[2,-1]"
81 [[ -f "$HOME/.axzsh.debug" ]] && echo "ยป $script_name:"
82 for plugin ($plugin_list); do
83 axzsh_load_plugin "$(basename "$plugin")" "$script_type"
85 unset script_name script_type plugin