#!/bin/bash
set -euo pipefail

for arg in "$@"; do
  case "$arg" in
    --help|-h)
      cat <<'EOF'
Usage: pull-all [options]

Pull latest changes for all repos matching *schmeeve* in ~/git/.

Options:
  -h, --help    Show this help message and exit
EOF
      exit 0
      ;;
  esac
done

GIT_HOME="${HOME}/git"

for dir in "${GIT_HOME}"/*/ "${HOME}/Dotfiles"; do
  if [ -d "${dir}/.git" ]; then
    repo=$(basename "${dir}")
    remote=$(git -C "${dir}" remote get-url origin 2>/dev/null || true)
    case "${remote}" in
      *schmeeve*)
        ;;
      *)
        echo "  Skipping (not your repo: ${remote})"
        continue
        ;;
    esac
    echo "=== ${repo} ==="
    git -C "${dir}" pull
  fi
done
