#!/bin/zsh

#################################################################################
# ZSH zle widget and custom function autloader 
#################################################################################
#
# Lets you load custom functions and zle widgets split into single files.
#
# zle widgets are stored in the "widgets" folder in your configuration directory
# (set with $ZDOTDIR, see manpage. defaults to /etc/zsh)
#
# functions are stored in the "functions" folder analogous.
#

ZWIDGETPATH=${ZWIDGETPATH:-"${ZDOTDIR:-/etc/zsh}/widgets"}
ZFUNCTIONPATH=${ZFUNCTIONPATH:-"${ZDOTDIR:-/etc/zsh}/functions"}
fpath+=( "${ZWIDGETPATH}" )
fpath+=( "${ZFUNCTIONPATH}" )

if [ -d $ZWIDGETPATH ]; then
	for i in $ZWIDGETPATH/*(N:t); do
		autoload -Uz  $i
		zle -N $i
	done
fi

if [ -d $ZFUNCTIONPATH ]; then
	for i in $ZFUNCTIONPATH/*(N:t); do
		autoload -Uz $i && $i
	done
fi