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"
20 "$AXZSH/default_plugins/$plugin"
23 [[ ! -d "$dname" ]] && continue
25 fname="$dname/$plugin.$type"
26 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
27 if [[ -r "$dname/$plugin.plugin.zsh" ]]; then
30 fname="$dname/$plugin.plugin.zsh"
31 elif [[ -r "$dname/init.zsh" ]]; then
34 fname="$dname/init.zsh"
38 if [[ -r "$fname" ]]; then
39 [[ -f "$HOME/.axzsh.debug" ]] \
40 && echo " - $plugin ($type) ..."
47 if [[ -f "$HOME/.axzsh.debug" ]]; then
48 # Show error message for all stages in "debug mode":
49 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
50 elif [[ "$type" == "zshrc" ]]; then
51 # Show error message for the "zshrc" stage:
52 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
57 # Make sure that "AXZSH" variable is set and exported
58 if [[ -z "$AXZSH" ]]; then
59 export AXZSH="$HOME/.axzsh"
60 if [[ -f "$HOME/.axzsh.debug" ]]; then
62 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
66 # Setup list of default plugins if not set already. This allows users to
67 # overwrite this list in their "~/.zshenv" file, for example.
68 typeset -U axzsh_default_plugins
69 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
70 axzsh_default_plugins=(
71 $AXZSH/default_plugins/*
75 # Setup list of plugins to load:
76 typeset -U plugin_list
79 $axzsh_default_plugins
85 # Read in all the plugins for the current "type":
86 for plugin ($plugin_list); do
87 axzsh_load_plugin "$(basename "$plugin")" "$script_type"
89 unset script_name script_type plugin