Skip to content

Instantly share code, notes, and snippets.

@harderthan
Created January 7, 2026 04:43
Show Gist options
  • Select an option

  • Save harderthan/719b3159e6758f80355054defe9271c7 to your computer and use it in GitHub Desktop.

Select an option

Save harderthan/719b3159e6758f80355054defe9271c7 to your computer and use it in GitHub Desktop.
watch sync with rync
#!/usr/bin/env bash
set -euo pipefail
DEBOUNCE_SEC="${DEBOUNCE_SEC:-0.2}"
SYNC_CMD="./sync_to_remote.sh" # https://gist.github.com/harderthan/d56aaf41bd7836fae011d74d55b46d4b
EXCLUDE_REGEX='(^|/)(\.git|__pycache__|\.venv|build|\.cache)(/|$)|(\.pyc$)'
sync_running=0
sync_pending=0
run_sync() {
sync_running=1
"${SYNC_CMD}"
echo "[watch_sync] synced"
sync_running=0
if [[ "${sync_pending}" -eq 1 ]]; then
sync_pending=0
run_sync
fi
}
inotifywait -m -r \
-e modify,create,delete,move,close_write \
--exclude "${EXCLUDE_REGEX}" \
--format '%w%f' . | while read -r _; do
sleep "${DEBOUNCE_SEC}"
if [[ "${sync_running}" -eq 1 ]]; then
sync_pending=1
else
run_sync
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment