Scoped var and function name when sourcing

This commit is contained in:
nebirhos 2012-03-26 23:13:47 +02:00
commit 172008ee26
2 changed files with 42 additions and 26 deletions

View file

@ -9,26 +9,29 @@ function omz_usage() {
echo " help Show this help" 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 shift 1
source $ZSH/tools/$COMMAND.sh $@ source $ZSH/tools/$OMZ_COMMAND.sh $@
;; ;;
* ) * )
shift 1 shift 1
if [ -x $ZSH/tools/$OMZ_COMMAND.sh ]; then
if [ -x $ZSH/tools/$COMMAND.sh ]; then zsh $ZSH/tools/$OMZ_COMMAND.sh $@
zsh $ZSH/tools/$COMMAND.sh $@
else else
omz_usage omz_usage
fi fi
;; ;;
'' | help )
omz_usage ;;
esac esac
# Clean global vars
unfunction omz_usage
unset OMZ_COMMAND

View file

@ -1,4 +1,4 @@
#!/bin/zsh -x #!/bin/zsh
function omz_plugin_usage() { function omz_plugin_usage() {
echo "Usage: omz plugin [options] [plugin]" echo "Usage: omz plugin [options] [plugin]"
@ -9,35 +9,48 @@ function omz_plugin_usage() {
echo " -h Show this help message" 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 do
case $Option in case $OMZ_OPTION in
l ) l ) ls $ZSH/plugins
ls $ZSH/plugins omz_plugin_exit_clean
return ;; return ;;
* ) omz_plugin_usage * ) omz_plugin_usage
return 1 ;; omz_plugin_exit_clean
return ;;
esac esac
done done
if [ -n "$1" ]; then if [ -n "$1" ]; then
PLUGIN="$ZSH/plugins/$1" OMZ_PLUGIN="$ZSH/plugins/$1"
if [ -d $PLUGIN ]; then if [ -d $OMZ_PLUGIN ]; then
fpath=($PLUGIN $fpath) fpath=($OMZ_PLUGIN $fpath)
source $PLUGIN/*.plugin.zsh
autoload -U compinit autoload -U compinit
compinit -i compinit -i
if [ -e $OMZ_PLUGIN/$1.plugin.zsh ]; then
source $OMZ_PLUGIN/$1.plugin.zsh
fi
echo "\033[0;32mPlugin $1 enabled" echo "\033[0;32mPlugin $1 enabled"
return
else else
echo "\033[1;31mPlugin $1 not found" echo "\033[1;31mPlugin $1 not found"
return 1
fi fi
else else
omz_plugin_usage; omz_plugin_usage
return 1
fi fi
# Clean global vars
omz_plugin_exit_clean
return