Skip to content

Instantly share code, notes, and snippets.

@slarwise
Created September 2, 2023 10:49
Show Gist options
  • Save slarwise/ed7f94f76e4002867011c98a235fa2ee to your computer and use it in GitHub Desktop.
Save slarwise/ed7f94f76e4002867011c98a235fa2ee to your computer and use it in GitHub Desktop.

Filewatcher

fswatch is a good program to react to file changes, e.g. run tests when files are updated. It's cross-platform.

fswatch path/to/file | xargs -n 1 bash_command
fswatch ./README.md | xargs -I {} -n 1 pandoc -o README.html README.md
fswatch -o ./*.js | xargs -I {} -n 1 npm test

See tldr fswatch for more examples. Use -v/--verbose to double-check that stuff is happening. -I {} is needed to either insert the filename in a particular place, or to not put it in at the end of the command. -o/--one-per-batch will batch changes together to one alert when many files are changed at the same time. -n 1 is only necessary if you are watching more than one file I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment