#!/usr/bin/env bash
set -euo pipefail
host="${LAPTOP_HOST:-brag-pipe-fur-kneel.emperor-ratio.ts.net}"
port="${LAPTOP_PORT:-2222}"
key="${LAPTOP_SSH_KEY:-$HOME/.ssh/id_ed25519_laptop_agent}"
ssh_cmd=(ssh -p "$port" -o BatchMode=yes -o IdentitiesOnly=yes)
if [[ -f "$key" ]]; then
  ssh_cmd+=( -i "$key" )
fi
if [[ $# -lt 2 ]]; then
  echo "usage: laptop-rsync <src> <dest> [extra rsync args...]" >&2
  echo "examples:" >&2
  echo "  laptop-rsync ${host}:/Users/sebas/Downloads/file ./" >&2
  echo "  laptop-rsync ./file ${host}:/Users/sebas/Downloads/" >&2
  exit 2
fi
rsync -av --progress -e "${ssh_cmd[*]}" "$@"
