Skip to content

Instantly share code, notes, and snippets.

@philipjohn
Last active May 6, 2025 09:57
Show Gist options
  • Save philipjohn/f28724f5f3c627e78e6c585d7074ccc4 to your computer and use it in GitHub Desktop.
Save philipjohn/f28724f5f3c627e78e6c585d7074ccc4 to your computer and use it in GitHub Desktop.
Watch the current folder for changes and sync them to somewhere
# USAGE: watch_sync [destination_folder]
# Watch and sync a folder
watch_sync() {
# The first and only argument is the folder to sync to.
TO=$(echo "$1" | sed 's/\/$//')
# We assume the current folder is the one to sync from.
FROM=$(pwd)
# Now sync changes every second.
while ( true ); do
rsync -a --delete --exclude '.git' --exclude 'node_modules' --exclude 'vendor' "$FROM/" "$TO/"
sleep 1
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment