#!/usr/bin/env bash
git config --local core.hooksPath "$PWD"/.githooks

test -d .direnv || mkdir -p .direnv
now="$(date +%Y-%m-%d)"
if ! test -s .direnv/pull-date || test "$now" != "$(cat .direnv/pull-date)"; then
  git reset flake.lock
  git restore flake.lock
  git pull --rebase --autostash
  grep -q "^=======" flake.lock && { git reset flake.lock; rm flake.lock; }
  nix flake update
  echo "$now" > .direnv/pull-date
fi


if ! test -f .remote.toml; then
  use flake .#envrc-local
else
  use flake .#envrc-remote
  echo
  just remote-current
  just remote-list
  echo
fi

if rg 'TODO' -q ; then
  echo "There are $(rg 'TODO' | wc -l ) 'TODO'"
fi

export QEMU_NET_OPTS="hostfwd=tcp::10022-:22,hostfwd=tcp::10080-:80,hostfwd=tcp::10443-:443"
