#autoload

#Define global values
#this restores the existing functionality without taking into account
#the recent sorcery config changes
if (( ! $+GRIMOIRE_DIR )) ; then
    typeset $(grep " GRIMOIRE_LIST=" /etc/sorcery/config | sed "s/.*GRIMOIRE_LIST=.*:-\(.*\)}/GRIMOIRE_LIST=\1/g")

    typeset -gA GRIMOIRE_DIR
    . $GRIMOIRE_LIST
fi

# load spell's list
typeset _spells_list
for i in $GRIMOIRE_DIR
_spells_list=(
    $_spells_list
    $(cut --delimiter=" " -f 1 $i/codex.index)
)

# Check are there spells, or not.
if [[ "$_spells_list" != . ]]; then
    compadd -P '' $_spells_list
else
    false
fi
