]> arthur.barton.de Git - ax-zsh.git/blob - ax.zsh
New plugin "std_options": Set standard ZSH options
[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                 grep
73                 history
74                 less
75                 ls
76                 prompt
77                 ssh
78                 std_aliases
79                 std_env
80                 std_options
81         )
82 fi
83
84 # Setup list of plugins to load:
85 typeset -U plugin_list
86 plugin_list=(
87         $AXZSH/core/[0-5]*
88         $axzsh_default_plugins
89         $axzsh_plugins
90         $plugins
91         $AXZSH/core/[6-9]*
92 )
93
94 # Read in all the plugins for the current "type":
95 for plugin ($plugin_list); do
96         axzsh_load_plugin "$(basename "$plugin")" "$script_type"
97 done
98 unset script_name script_type plugin
99 unset plugin_list