]> arthur.barton.de Git - ax-zsh.git/blob - ax.zsh
Show a warning message when plugins can't be found
[ax-zsh.git] / ax.zsh
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # Copyright (c) 2015 Alexander Barton <alex@barton.de>
3
4 # Load plugin code of a given type.
5 # - $1: plugin name
6 # - $2: plugin type (optional; defaults to "zshrc")
7 function axzsh_load_plugin {
8         plugin="$1"
9         [[ -z "$2" ]] && type="zshrc" || type="$2"
10
11         for dname in \
12                 "$AXZSH_PLUGIN_D/$plugin" \
13                 "$AXZSH/plugins/$plugin" \
14                 "$AXZSH/core/$plugin" \
15         ; do
16                 [[ ! -d "$dname" ]] && continue
17
18                 fname="$dname/$plugin.$type"
19                 if [[ ! -r "$fname" && "$type" == "zshrc" ]]; then
20                         if [[ -r "$dname/$plugin.plugin.zsh" ]]; then
21                                 # Oh My ZSH plugin
22                                 type="plugin.zsh"
23                                 fname="$dname/$plugin.plugin.zsh"
24                         elif [[ -r "$dname/init.zsh" ]]; then
25                                 # Prezto module
26                                 type="init.zsh"
27                                 fname="$dname/init.zsh"
28                         fi
29                 fi
30
31                 if [[ -r "$fname" ]]; then
32                         [[ -f "$HOME/.axzsh.debug" ]] \
33                                 && echo "   - $plugin ($type) ..."
34                         source "$fname"
35                         return 0
36                 fi
37                 return 0
38         done
39         # Plugin not found!
40         if [[ -f "$HOME/.axzsh.debug" ]]; then
41                 # Show error message for all stages in "debug mode":
42                 echo "AX-ZSH plugin \"$plugin\" not found (type \"$type\")!" >&2
43         elif [[ "$type" == "zshrc" ]]; then
44                 # Show error message for the "zshrc" stage:
45                 echo "AX-ZSH plugin \"$plugin\" not found, skipped!" >&2
46         fi
47         return 1
48 }
49
50 # Make sure that "AXZSH" variable is set and exported
51 if [[ -z "$AXZSH" ]]; then
52         export AXZSH="$HOME/.axzsh"
53         [[ -f "$HOME/.axzsh.debug" ]] && echo "AXZSH=$AXZSH"
54 fi
55
56 # Setup list of default plugins if not set already. This allows users to
57 # overwrite this list in their "~/.zshenv" file, for example.
58 typeset -U axzsh_default_plugins
59 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
60         axzsh_default_plugins=(
61                 byebye
62                 completion
63                 correction
64                 history
65                 ls
66                 prompt
67                 ssh
68                 std_aliases
69                 std_env
70         )
71 fi
72
73 # Setup list of plugins to load:
74 typeset -U plugin_list
75 plugin_list=(
76         $AXZSH/core/[0-5]*
77         $axzsh_default_plugins
78         $axzsh_plugins
79         $plugins
80         $AXZSH/core/[6-9]*
81 )
82
83 # Read in all the plugins for the current "type":
84 script_name="$(basename -- "${(%):-%N}")"
85 script_type="$script_name[2,-1]"
86 [[ -f "$HOME/.axzsh.debug" ]] && echo "ยป $script_name:"
87 for plugin ($plugin_list); do
88         axzsh_load_plugin "$(basename "$plugin")" "$script_type"
89 done
90 unset script_name script_type plugin
91 unset plugin_list