# install zinit
if ! source "$ZDOTDIR/zinit.zsh"; then
    print -u2 "zinit: failed to initialize; skipping plugin configuration"
    return 1
fi

zinit light zdharma-continuum/zinit-annex-bin-gem-node
zinit light zdharma-continuum/zinit-annex-binary-symlink

zinit wait lucid light-mode id-as depth'1' for \
    wintermi/zsh-brew \
    hlissner/zsh-autopair \
    Aloxaf/fzf-tab \
    atinit'zicompinit; zicdreplay -q' \
        zdharma-continuum/fast-syntax-highlighting \
    atload'_zsh_autosuggest_start' \
        zsh-users/zsh-autosuggestions

zinit id-as from'gh-r' lbin'!' completions for \
    lsd-rs/lsd \
    micro-editor/micro \
    mv'**/bat.zsh -> _bat' \
        @sharkdp/bat

zinit for \
    id-as \
    as'completion' \
    from'gh-r' \
    mv'**/_fastfetch -> _fastfetch' \
    atpull'%atclone' \
    lbin'!**bin/fastfetch -> fastfetch' \
    @fastfetch-cli/fastfetch

zinit for \
    id-as \
    from'gh-r' \
    atclone'./zoxide init zsh > init.zsh' \
    atpull'%atclone' \
    lbin'!' \
    @ajeetdsouza/zoxide

# pick the correct fnm release asset for this OS/arch
if [[ "$OSTYPE" == darwin* ]]; then
    _fnm_asset='fnm-macos.zip'
elif [[ "$(uname -m)" == (aarch64|arm64) ]]; then
    _fnm_asset='fnm-arm64.zip'
else
    _fnm_asset='fnm-linux.zip'
fi
zinit for \
    id-as \
    from'gh-r' \
    bpick"$_fnm_asset" \
    atclone'
        ./fnm env --use-on-cd --shell zsh > init.zsh; \
        ./fnm completions --shell zsh > _fnm;
    ' \
    atpull'%atclone' \
    blockf \
    sbin'fnm' \
    @Schniz/fnm

zinit for \
    id-as \
    from'gh-r' \
    atclone'
        ./starship init zsh > init.zsh; \
        ./starship completions zsh > _starship;
    ' \
    atpull'%atclone' \
    sbin'starship' \
    @starship/starship

zinit for \
    id-as \
    from'gh-r' \
    atclone'./fzf --zsh > init.zsh' \
    atpull'%atclone' \
    lbin'!fzf' \
    @junegunn/fzf

for script in $ZDOTDIR/config/*.zsh; do
    source "$script"
done
