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 {
13 dname="$(readlink "$1")" || dname="$1"
14 plugin="$(basename "$dname")"
15 [[ -z "$2" ]] && type="zshrc" || type="$2"
16 fname="$dname/$plugin.$type"
18 if [[ ! -d "$dname" ]]; then
20 if [[ -f "$HOME/.axzsh.debug" ]]; then
21 # Show error message for all stages in "debug mode":
22 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
23 elif [[ "$type" == "zshrc" ]]; then
24 # Show error message for the "zshrc" stage:
25 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
30 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
31 if [[ -r "$dname/$plugin.plugin.zsh" ]]; then
34 fname="$dname/$plugin.plugin.zsh"
35 elif [[ -r "$dname/init.zsh" ]]; then
38 fname="$dname/init.zsh"
42 if [[ -r "$fname" ]]; then
43 [[ -f "$HOME/.axzsh.debug" ]] \
44 && echo " - $plugin ($type) ..."
48 # It is a success, even if only the plugin directory (and no script!)
49 # exists at all! Rationale: The script could be of an other type ...
53 # Make sure that "AXZSH" variable is set and exported
54 if [[ -z "$AXZSH" ]]; then
55 export AXZSH="$HOME/.axzsh"
56 if [[ -f "$HOME/.axzsh.debug" ]]; then
58 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
62 # Setup list of plugins to load:
63 typeset -U plugin_list
66 "$AXZSH/active_plugins/"*(N)
70 # Read in all the plugins for the current "type":
71 for plugin ($plugin_list); do
72 axzsh_load_plugin "$plugin" "$script_type"
74 unfunction axzsh_load_plugin
75 unset script_name script_type plugin