diff --git a/bin/omz.sh b/bin/omz.sh index 4a4d2f4ec..2ecf81a51 100755 --- a/bin/omz.sh +++ b/bin/omz.sh @@ -9,26 +9,29 @@ function omz_usage() { echo " help Show this help" } -COMMAND=$1 -case $COMMAND in +OMZ_COMMAND=$1 +case $OMZ_COMMAND in - plugin ) # we need source to enable autocompletion + '' | help ) + omz_usage + ;; + + plugin ) shift 1 - source $ZSH/tools/$COMMAND.sh $@ + source $ZSH/tools/$OMZ_COMMAND.sh $@ ;; * ) shift 1 - - if [ -x $ZSH/tools/$COMMAND.sh ]; then - zsh $ZSH/tools/$COMMAND.sh $@ + if [ -x $ZSH/tools/$OMZ_COMMAND.sh ]; then + zsh $ZSH/tools/$OMZ_COMMAND.sh $@ else omz_usage fi ;; - - '' | help ) - omz_usage ;; - esac + +# Clean global vars +unfunction omz_usage +unset OMZ_COMMAND diff --git a/tools/plugin.sh b/tools/plugin.sh index d1410afce..bedfb86ca 100755 --- a/tools/plugin.sh +++ b/tools/plugin.sh @@ -1,4 +1,4 @@ -#!/bin/zsh -x +#!/bin/zsh function omz_plugin_usage() { echo "Usage: omz plugin [options] [plugin]" @@ -9,35 +9,48 @@ function omz_plugin_usage() { echo " -h Show this help message" } +function omz_plugin_exit_clean() { + unset OMZ_OPTION + unset OMZ_PLUGIN + unfunction omz_plugin_usage + unfunction omz_plugin_exit_clean + return +} -while getopts ":lh" Option + +OPTIND=0 +while getopts "lh" OMZ_OPTION do - case $Option in - l ) - ls $ZSH/plugins + case $OMZ_OPTION in + l ) ls $ZSH/plugins + omz_plugin_exit_clean return ;; * ) omz_plugin_usage - return 1 ;; + omz_plugin_exit_clean + return ;; + esac done - if [ -n "$1" ]; then - PLUGIN="$ZSH/plugins/$1" + OMZ_PLUGIN="$ZSH/plugins/$1" - if [ -d $PLUGIN ]; then - fpath=($PLUGIN $fpath) - source $PLUGIN/*.plugin.zsh + if [ -d $OMZ_PLUGIN ]; then + fpath=($OMZ_PLUGIN $fpath) autoload -U compinit compinit -i + if [ -e $OMZ_PLUGIN/$1.plugin.zsh ]; then + source $OMZ_PLUGIN/$1.plugin.zsh + fi echo "\033[0;32mPlugin $1 enabled" - return else echo "\033[1;31mPlugin $1 not found" - return 1 fi else - omz_plugin_usage; - return 1 + omz_plugin_usage fi + +# Clean global vars +omz_plugin_exit_clean +return