#!/bin/zsh
die() {
	print -r - "$@"
	exit 1
}

if [[ -z $SNAP_SRCS ]]; then
	SNAP_SRCS=$1;shift
fi
SNAP_SRCS=${SNAP_SRCS%%/}

if [[ -z $SNAP_DST ]]; then
	SNAP_DST=$1;shift
fi
SNAP_DST=${SNAP_DST%%/}

typeset -A snapshots
for ts in ${(f)"$(snap.list $SNAP_SRCS/)"}; do
	snapshots[$ts]=$SNAP_SRCS/$ts
done

for ts in ${(f)"$(snap.list $SNAP_DST/)"}; do
	unset "snapshots[$ts]"
done

export SNAP_SRC SNAP_DST
for SNAP_SRC in $snapshots; do
	if [[ -o xtrace ]]; then
		zsh -x $commands[snap.push.single] "$@"
	else
		snap.push.single "$@"
	fi
done