1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015 Alexander Barton <alex@barton.de>
4 script_name="${${(%):-%N}:t}"
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 {
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 [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
43 # Add plugin function path when folder exists
44 axzsh_fpath+=("$dname/functions")
47 if [[ -r "$fname" ]]; then
48 [[ -f "$HOME/.axzsh.debug" ]] \
49 && echo " - $plugin ($type) ..."
53 # It is a success, even if only the plugin directory (and no script!)
54 # exists at all! Rationale: The script could be of an other type ...
58 # Make sure that "AXZSH" variable is set and exported
59 if [[ -z "$AXZSH" ]]; then
60 export AXZSH="$HOME/.axzsh"
61 if [[ -f "$HOME/.axzsh.debug" ]]; then
63 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
67 # Setup list of plugins to load:
68 typeset -U plugin_list
71 "$AXZSH/active_plugins/"*(N)
75 # Read in all the plugins for the current "type":
76 for plugin ($plugin_list); do
77 axzsh_load_plugin "$plugin" "$script_type"
79 unfunction axzsh_load_plugin
80 unset script_name script_type plugin