cachedir=${XDG_CACHE_HOME:-$HOME/.cache}/zsh
datadir=${XDG_DATA_HOME:-$HOME/.local/share}/zsh
confdir=$(dirname $(print -P %N))
test -d $cachedir || mkdir -p $cachedir
test -d $datadir || mkdir -p $datadir

# Enable Powerlevel10k instant prompt. Should stay close to the top of ${ZDOTDIR:-${HOME}}/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${cachedir}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${cachedir}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

ZIM_HOME=$datadir/zim
test -d $ZIM_HOME  || mkdir -p $ZIM_HOME
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
    wget -O ${ZIM_HOME}/zimfw.zsh \
        https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi

for cf in ~/.config/zsh/include/*.zsh ; do
	source $cf
done

if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
  source ${ZIM_HOME}/zimfw.zsh init -v
fi

source ${ZIM_HOME}/init.zsh


if [[ $confdir/theme/gruvbox.ini -nt $(fast-theme -w && pwd )/current_theme.zsh ]]
then
    echo "Refreshing theme"
    fast-theme $confdir/theme/gruvbox.ini
fi
unset _fast_theme

if (( ${+ZIM_UPDATE} ))
then
    zimfw update -v
fi

unset cachedir datadir confdir
