1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015 Alexander Barton <alex@barton.de>
4 script_name="$(basename -- "${(%):-%N}")"
5 script_type="$script_name[2,-1]"
7 [[ -f "$HOME/.axzsh.debug" ]] && echo "ยป $script_name:"
9 # Load plugin code of a given type.
11 # - $2: plugin type (optional; defaults to "zshrc")
12 function axzsh_load_plugin {
14 [[ -z "$2" ]] && type="zshrc" || type="$2"
17 "$AXZSH_PLUGIN_D/$plugin"
19 "$AXZSH/plugins/$plugin"
22 [[ ! -d "$dname" ]] && continue
24 fname="$dname/$plugin.$type"
25 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
26 if [[ -r "$dname/$plugin.plugin.zsh" ]]; then
29 fname="$dname/$plugin.plugin.zsh"
30 elif [[ -r "$dname/init.zsh" ]]; then
33 fname="$dname/init.zsh"
37 if [[ -r "$fname" ]]; then
38 [[ -f "$HOME/.axzsh.debug" ]] \
39 && echo " - $plugin ($type) ..."
46 if [[ -f "$HOME/.axzsh.debug" ]]; then
47 # Show error message for all stages in "debug mode":
48 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
49 elif [[ "$type" == "zshrc" ]]; then
50 # Show error message for the "zshrc" stage:
51 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
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
61 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
65 # Setup list of default plugins if not set already. This allows users to
66 # overwrite this list in their "~/.zshenv" file, for example.
67 typeset -U axzsh_default_plugins
68 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
69 axzsh_default_plugins=(
83 # Setup list of plugins to load:
84 typeset -U plugin_list
87 $axzsh_default_plugins
93 # Read in all the plugins for the current "type":
94 for plugin ($plugin_list); do
95 axzsh_load_plugin "$(basename "$plugin")" "$script_type"
97 unset script_name script_type plugin