#!/usr/bin/env bash

set -e

DOTFILES_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"

if ! command -v paru &>/dev/null; then
  echo "Installing paru"
  sudo pacman -S base-devel git --needed --noconfirm

  TEMP_DIR=$(mktemp -d)

  git clone https://aur.archlinux.org/paru-bin.git $TEMP_DIR/paru-bin
  cd $TEMP_DIR/paru-bin

  makepkg -si --noconfirm
fi

echo "Installing packages"
sudo -v
paru -S --noconfirm --needed - <$DOTFILES_DIR/packages.txt

echo "Changing default shell"
sudo chsh -s /bin/zsh $USER

echo "Setting nautilus as default file manager"
xdg-mime default org.gnome.nautilus.desktop inode/directory

echo "Setting default git branch to \"main\""
git config --global init.defaultBranch main

echo "Applying arrpc fix"
sudo cp /usr/lib/systemd/user/arrpc.service /etc/systemd/system/arrpc.service
sudo systemctl enable arrpc --now

echo "Applying stow"
cd $DOTFILES_DIR
stow fastfetch fuzzel ghostty godot hyfetch kvantum mangohud niri nvim qt6ct zsh
