From 8f17d3c1b8de66d0e3be5c09260b08cf36e14241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 21 May 2014 10:59:29 +0100 Subject: [PATCH 1/2] 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 --- oh-my-zsh.sh | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 3c0f4f8f5..59350896b 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -27,14 +27,29 @@ is_plugin() { test -f $base_dir/plugins/$name/$name.plugin.zsh \ || test -f $base_dir/plugins/$name/_$name } + +add_plugin_fpath() { + local plugin=$1 + if is_plugin $ZSH_CUSTOM $plugin; then + fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) + elif is_plugin $ZSH $plugin; then + fpath=($ZSH/plugins/$plugin $fpath) + 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 - if is_plugin $ZSH_CUSTOM $plugin; then - fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) - elif is_plugin $ZSH $plugin; then - fpath=($ZSH/plugins/$plugin $fpath) - fi + add_plugin_fpath $plugin done # Figure out the SHORT hostname @@ -54,13 +69,16 @@ compinit -i -d "${ZSH_COMPDUMP}" # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do - 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 + source_plugin_zsh $plugin 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/ for config_file ($ZSH_CUSTOM/*.zsh(N)); do source $config_file From bb15337e9320961b89456e5b63beca4e71b98f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sun, 20 Jul 2014 17:25:48 +0100 Subject: [PATCH 2/2] Check if plugin already loaded in load_plugin * oh-my-zsh.sh (sourced_plugins): New variable, a hashtable. (source_plugin_zsh): Add to sourced_plugins. (load_plugin): Check sourced_plugins. --- oh-my-zsh.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 59350896b..a0409ad0f 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -37,6 +37,9 @@ add_plugin_fpath() { fi } +sourced_plugins={} +typeset -A sourced_plugins + source_plugin_zsh() { local plugin=$1 if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then @@ -44,6 +47,7 @@ source_plugin_zsh() { elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then source $ZSH/plugins/$plugin/$plugin.plugin.zsh fi + sourced_plugins[$1]=$1 } # Add all defined plugins to fpath. This must be done @@ -73,10 +77,13 @@ for plugin ($plugins); do done load_plugin() { - fpath=($ZSH/functions $ZSH/completions $fpath) - add_plugin_fpath $1 - compinit -i - source_plugin_zsh $1 + if [ -z ${sourced_plugins[$1]} ]; then + add_plugin_fpath $1 + compinit -i + source_plugin_zsh $1 + else + echo "[oh-my-zsh] '$1' already loaded." + fi } # Load all of your custom configurations from custom/