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