#!/usr/bin/env bash
sources=("$PWD/config/" "$PWD/etc/" "$PWD/home/" "$PWD/qutebrowser/")
targets=("$HOME/.config/" "/etc/" "$HOME/" "$HOME/.config/qutebrowser/")
length=${#sources[@]}

packages="brightnessctl hyprland hyprlock hyprpaper i3status-rust kitty mpv neovim obs-studio qutebrowser ttc-iosevka ttf-nerd-fonts-symbols-mono yazi noto-fonts-emoji"
# TODO: need to address need to run as sudo to add symlink to certain folders, maybe ask in outer loop when sudo is needed and set a variable

dependencies() {
  read -p "Install the following packages : $packages ? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || break
  echo hello
  sudo pacman -S $packages
}

update() {
  for ((i = 0; i < length; i++)); do

    source=${sources[i]}
    target=${targets[i]}

    for folder in $(ls $source -a); do
      if [ -e "$target$folder" ]; then
        echo "The file '$target$folder' exists."
      else
        if [ -w "$target" ]; then
          ln -s $source$folder $target$folder
        else
          read -p "write in : $target$folder ? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || break
          sudo ln -s $source$folder $target$folder
        fi
      fi
    done
  done
}

update
