#!/usr/bin/zsh


echo -n "[*] Do you want to install all packages via pacman? [y/n] "
read yesno

if [[ "$yesno" == "y" ]]; then
    echo "[*] Installing most popular tools"
    # most important tools that are _always_ needed
    sudo pacman -Sy fzf fd neovim ripgrep nmap hexyl ctags git podman ueberzug duf exa i3blocks udiskie alacritty rofi firefox python-pip vifm zathura zathura-pdf-mupdf sxiv feh xclip flameshot
fi


# .zpretzo
echo -n "[*] Do you want to install zpretzo? [y/n] "
read yesno

if [[ "$yesno" == "y" ]]; then
    cd $HOME
    [ ! -d "$HOME/.zprezto" ] && git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"

    setopt EXTENDED_GLOB
    for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
      rm -rf "${ZDOTDIR:-$HOME}/.${rcfile:t}"
      echo "[*] Symlinking $rcfile -> ${ZDOTDIR:-$HOME}/.${rcfile:t}"
      ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
    done
fi


echo -n "[*] Copy (and overwrite) dotfiles? [y/n] "
read yesno

if [[ "$yesno" == "y" ]]; then
    backup_dir=/tmp/dotfiles-backup-$(date "+%H%M%S")
    rsync --backup --backup-dir $backup_dir --exclude profiles --exclude .git/ --exclude install.sh -r . $HOME
    echo "[+] Dotfiles installed :) Backup available @ $backup_dir"
fi


echo -n "[*] Do you want to pywal? [y/n] "
read yesno

if [[ "$yesno" == "y" ]]; then
    sudo pip3 install pywal
fi



# Installing custom profile
echo -n "[*] Do you want to install custom profile? [y/n] "
read yesno

if [[ "$yesno" == "y" ]]; then

    pf=$(ls ./profiles)
    profiles=(${=pf})


    for i ("$profiles[@]") ; do
        print -r -- "> $i"
    done


    echo -n "[*] Enter profile name: "
    read profilename


    if [[ " ${profiles[*]} " =~ " ${profilename} " ]];
    then
        echo "[+] Found profile, copying files..."
        backup_dir=/tmp/dotfiles-backup-profile-$(date "+%H%M%S")
        rsync --backup --backup-dir $backup_dir --exclude .git/ --exclude install.sh -r "./profiles/$profilename/" $HOME
    else
        echo "[-] Profile not found, continuing"
    fi
fi

# Creating vim folders
mkdir -p $HOME/.config/nvim/backups
mkdir -p $HOME/.config/nvim/undo

# Creating other needed folders
mkdir -p $HOME/documents
mkdir -p $HOME/documents/tools
mkdir -p $HOME/documents/bin
# setup SSH Folders & default import rule
mkdir -p $HOME/.ssh
mkdir -p $HOME/.ssh/config.d/
echo "Include config.d/*" > $HOME/.ssh/config




# Cleaning default folders
rm -rf $HOME/Documents
rm -rf $HOME/Pictures
rm -rf $HOME/Public
rm -rf $HOME/Templates
rm -rf $HOME/Music
rm -rf $HOME/Videos
rm -rf $HOME/Desktop


echo "[INFO] Switch the default downloads folder to 'downloads' in Firefox!"
echo "[+] Done :)"
