#!/bin/bash

required_progs=('zsh' 'vim' 'xxd' 'dig' 'curl' 'wezterm')

files_to_link=('.vimrc' '.zsh' '.zshrc' '.wezterm' '.wezterm.lua')

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

check_and_backup() {
  filepath="$1"
  if [[ -f "$filepath" ]]; then
    echo "Found existing $filepath, will backup to ~/shell_backup/$filepath"
    mkdir -p ~/shell_backup/
    cp "$filepath" ~/shell_backup/
  fi
}

for prog in "${required_progs[@]}" ; do
  if ! command -v "$prog" > /dev/null ; then
    echo "WARN: $prog not installed or not in PATH."
  fi
done

for file in "${files_to_link[@]}"; do
  check_and_backup "$HOME/$file"

  echo "ln -s $SCRIPT_DIR/$file $HOME/$file" 
done
