#!/usr/bin/env zsh

__import "core/core"
__import "print/print"

local main
main="zplug/zplug"

__zplug::print::print::put "$fg_bold[default] * zplug self management$reset_color\n"

if __check__ "$main"; then
    __update__ "$main"
else
    if ! __zplug::core::core::zpluged "$main"; then
        __add__ "$main"
    fi
    __install__ "$main"
fi

ln -snf \
    "$ZPLUG_REPOS/$main/init.zsh" \
    "$ZPLUG_HOME/init.zsh"

if (( $status == 0)) && [[ -d $ZPLUG_REPOS/$main ]]; then
    __zplug::print::print::put "$fg[green]Everything is ready. "
    __zplug::print::print::put "$fg_bold[default]($ZPLUG_HOME/zplug)$reset_color\n"
else
    __zplug::print::print::die "$fg[red]Error occured (see ${(%):-"%U"}$_ZPLUG_URL${(%):-"%u"})$reset_color\n"
    return 1
fi
