Skip to content

Instantly share code, notes, and snippets.

@mitchellrj
Last active August 29, 2015 14:07
Show Gist options
  • Save mitchellrj/55d0d8790f51503e8984 to your computer and use it in GitHub Desktop.
Save mitchellrj/55d0d8790f51503e8984 to your computer and use it in GitHub Desktop.
Script to watch a file for modifications and revert it immediately
#!/bin/bash
#
# Usage: watch-and-revert.sh filename
#
BACKUP="$(dirname $1)/.backup-$(basename $1)"
function cleanup {
rm $BACKUP
}
trap cleanup EXIT
cat $1 > $BACKUP
while true; do
inotifywait -qo /dev/null -e close_write $1
cat $BACKUP > $1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment