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