1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015-2016 Alexander Barton <alex@barton.de>
4 script_name="${${(%):-%N}:t}"
5 script_type="$script_name[2,-1]"
7 # Load plugin code of a given type.
9 # - $2: plugin type (optional; defaults to "zshrc")
10 function axzsh_load_plugin {
13 [[ -z "$2" ]] && type="zshrc" || type="$2"
14 fname="$dname/$plugin.$type"
16 [[ "$plugin" =~ "#" ]] && plugin=$(echo $plugin | cut -d'#' -f2-)
18 if [[ ! -d "$dname" ]]; then
20 if [[ -n "$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.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
32 # Native AX-ZSH plugin, but for different stage. Skip it!
34 elif [[ -r "$dname/$plugin.plugin.zsh" ]]; then
37 fname="$dname/$plugin.plugin.zsh"
38 elif [[ -r "$dname/init.zsh" ]]; then
41 fname="$dname/init.zsh"
43 echo "AX-ZSH plugin type of \"$plugin\" unknown, skipped!" >&2
47 if [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
48 # Add plugin function path when folder exists
49 axzsh_fpath+=("$dname/functions")
52 if [[ -r "$fname" ]]; then
53 [[ -n "$AXZSH_DEBUG" ]] \
54 && echo " - $plugin ($type) ..."
58 # It is a success, even if only the plugin directory (and no script!)
59 # exists at all! Rationale: The script could be of an other type ...
63 # Make sure that "AXZSH" variable is set and exported
64 if [[ -z "$AXZSH" ]]; then
65 export AXZSH="$HOME/.axzsh"
66 if [[ -f "$HOME/.axzsh.debug" ]]; then
69 echo "AXZSH_DEBUG=$AXZSH_DEBUG"
70 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
74 [[ -n "$AXZSH_DEBUG" ]] && echo "ยป $script_name:"
76 # Setup list of plugins to load:
77 typeset -U plugin_list
80 "$AXZSH/active_plugins/"*(N)
84 # Read in all the plugins for the current "type":
85 for plugin ($plugin_list); do
86 axzsh_load_plugin "$plugin" "$script_type"
88 unfunction axzsh_load_plugin
89 unset script_name script_type plugin