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 # Strip repository prefix (like "alexbarton#test-plugin"):
17 [[ "$plugin" =~ "#" ]] && plugin=$(echo $plugin | cut -d'#' -f2-)
19 # "short plugin name": strip ".zsh" suffix:
20 plugin_short=${plugin%.zsh}
22 if [[ ! -d "$dname" ]]; then
24 if [[ -n "$AXZSH_DEBUG" ]]; then
25 # Show error message for all stages in "debug mode":
26 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
27 elif [[ "$type" == "zshrc" ]]; then
28 # Show error message for the "zshrc" stage:
29 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
34 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
35 if [[ -r "$dname/$plugin.zprofile" || -r "$dname/$plugin.zlogout" ]]; then
36 # Native AX-ZSH plugin, but for different stage. Skip it!
38 elif [[ -r "$dname/${plugin_short}.plugin.zsh" ]]; then
41 fname="$dname/${plugin_short}.plugin.zsh"
42 elif [[ -r "$dname/init.zsh" ]]; then
45 fname="$dname/init.zsh"
47 echo "AX-ZSH plugin type of \"$plugin\" unknown, skipped!" >&2
52 if [[ "$type" == "zprofile" && -d "$dname/functions" ]]; then
53 # Add plugin function path when folder exists
54 [[ -n "$AXZSH_DEBUG" ]] \
55 && echo " - $plugin ($type): functions ..."
56 axzsh_fpath+=("$dname/functions")
59 if [[ -r "$fname" ]]; then
61 [[ -n "$AXZSH_DEBUG" ]] \
62 && echo " - $plugin ($type) ..."
66 # It is a success, even if only the plugin directory (and no script!)
67 # exists at all! Rationale: The script could be of an other type ...
71 # Make sure that "AXZSH" variable is set and exported
72 if [[ -z "$AXZSH" ]]; then
73 export AXZSH="$HOME/.axzsh"
74 if [[ -f "$HOME/.axzsh.debug" ]]; then
77 echo "AXZSH_DEBUG=$AXZSH_DEBUG"
78 echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
82 [[ -n "$AXZSH_DEBUG" ]] && echo "ยป $script_name:"
84 # Setup list of plugins to load:
85 typeset -U plugin_list
88 "$AXZSH/active_plugins/"*(N)
92 # Read in all the plugins for the current "type":
93 for plugin ($plugin_list); do
94 axzsh_load_plugin "$plugin" "$script_type"
98 unfunction axzsh_load_plugin
99 unset script_name script_type plugin