Refactor plugin-loading functionality

* oh-my-zsh.sh (add_plugin_fpath, source_plugin_zsh)
(load_plugin): New functions.
[top]: Use source_plugin_zsh and add_plugin_fpath
This commit is contained in:
João Távora 2014-05-21 10:59:29 +01:00
parent 3913106b2e
commit 8f17d3c1b8

View File

@ -27,14 +27,29 @@ is_plugin() {
test -f $base_dir/plugins/$name/$name.plugin.zsh \ test -f $base_dir/plugins/$name/$name.plugin.zsh \
|| test -f $base_dir/plugins/$name/_$name || test -f $base_dir/plugins/$name/_$name
} }
# Add all defined plugins to fpath. This must be done
# before running compinit. add_plugin_fpath() {
for plugin ($plugins); do local plugin=$1
if is_plugin $ZSH_CUSTOM $plugin; then if is_plugin $ZSH_CUSTOM $plugin; then
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
elif is_plugin $ZSH $plugin; then elif is_plugin $ZSH $plugin; then
fpath=($ZSH/plugins/$plugin $fpath) fpath=($ZSH/plugins/$plugin $fpath)
fi fi
}
source_plugin_zsh() {
local plugin=$1
if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
source $ZSH/plugins/$plugin/$plugin.plugin.zsh
fi
}
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin ($plugins); do
add_plugin_fpath $plugin
done done
# Figure out the SHORT hostname # Figure out the SHORT hostname
@ -54,13 +69,16 @@ compinit -i -d "${ZSH_COMPDUMP}"
# Load all of the plugins that were defined in ~/.zshrc # Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do for plugin ($plugins); do
if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then source_plugin_zsh $plugin
source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
source $ZSH/plugins/$plugin/$plugin.plugin.zsh
fi
done done
load_plugin() {
fpath=($ZSH/functions $ZSH/completions $fpath)
add_plugin_fpath $1
compinit -i
source_plugin_zsh $1
}
# Load all of your custom configurations from custom/ # Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do for config_file ($ZSH_CUSTOM/*.zsh(N)); do
source $config_file source $config_file