#!/bin/sh

# clean + prepare local dirs
rm -rf ~/.cache ~/.config/_cache /tmp/${USER}-cache
rm -rf ~/.fdignore ~/.fzf.bash ~/.fzf.zsh ~/.gitconfig ~/.gitignore ~/.history ~/.tmux.conf ~/.vim* ~/.zcomp* ~/.zsh* ~/.local/share/nvim ~/.local/state/nvim
mkdir -p /tmp/${USER}-cache/ ~/.config ~/.local/bin ~/.local/share
chmod 700 /tmp/${USER}-cache

# export XDG stuff for later use
export XDG_CACHE_HOME=/tmp/${USER}-cache
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_STATE_HOME=$HOME/.local/state

# prepare repository
mkdir -p $XDG_DATA_HOME/repos
rm -rf $XDG_DATA_HOME/repos/dotfiles
git clone --recurse https://git.insomniac.pl/ftpd/dotfiles $XDG_DATA_HOME/repos/dotfiles

# configs
for i in astronvim fd htop starship.toml tmux; do
  rm -rf $XDG_CONFIG_HOME/${i}
  ln -sf $XDG_DATA_HOME/repos/dotfiles/${i} $XDG_CONFIG_HOME
done

# astronvim
rm -rf ~/.config/nvim $XDG_DATA_HOME/repos/AstroNvim
git clone --depth 1 https://github.com/AstroNvim/AstroNvim $XDG_DATA_HOME/repos/AstroNvim
ln -sf $XDG_DATA_HOME/repos/AstroNvim $XDG_CONFIG_HOME/nvim

## zsh
### modules
mkdir -p $XDG_DATA_HOME/repos/zsh_modules
rm -rf $XDG_DATA_HOME/repos/zsh_modules/*
for module in mfaerevaag/wd zdharma-continuum/fast-syntax-highlighting; do
  git clone https://github.com/${module} $XDG_DATA_HOME/repos/zsh_modules/${module#*/}
done
### config
rm -rf $XDG_CONFIG_HOME/zsh
ln -sf $XDG_DATA_HOME/repos/dotfiles/zsh $XDG_CONFIG_HOME
