]> arthur.barton.de Git - ax-zsh.git/blob - ax.zsh
Add "std_env" plugin to the list of default plugins
[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         [[ -f "$HOME/.axzsh.debug" ]] \
40                 && echo "Plugin \"$plugin\" not found (type \"$type\")!" >/dev/stderr
41         return 1
42 }
43
44 # Make sure that "AXZSH" variable is set and exported
45 if [[ -z "$AXZSH" ]]; then
46         export AXZSH="$HOME/.axzsh"
47         [[ -f "$HOME/.axzsh.debug" ]] && echo "AXZSH=$AXZSH"
48 fi
49
50 # Setup list of default plugins if not set already. This allows users to
51 # overwrite this list in their "~/.zshenv" file, for example.
52 typeset -U axzsh_default_plugins
53 if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
54         axzsh_default_plugins=(
55                 byebye
56                 completion
57                 correction
58                 history
59                 ls
60                 prompt
61                 ssh
62                 std_aliases
63                 std_env
64         )
65 fi
66
67 # Setup list of plugins to load:
68 typeset -U plugin_list
69 plugin_list=(
70         $AXZSH/core/[0-5]*
71         $axzsh_default_plugins
72         $axzsh_plugins
73         $plugins
74         $AXZSH/core/[6-9]*
75 )
76
77 # Read in all the plugins for the current "type":
78 script_name="$(basename -- "${(%):-%N}")"
79 script_type="$script_name[2,-1]"
80 [[ -f "$HOME/.axzsh.debug" ]] && echo "ยป $script_name:"
81 for plugin ($plugin_list); do
82         axzsh_load_plugin "$(basename "$plugin")" "$script_type"
83 done
84 unset script_name script_type plugin
85 unset plugin_list