A simple filesystem watcher
14 Feb 2014watch-fs is a small, simple tool that watches a directory and runs commands when files change.
Lots of similar tools already exist - nodemon, my own spotter, inotifywait. Each of them have been to complex to use quickly, or in the case of nodemon, are geared towards a specific use case.
watch-fs aims to work as simply as possible out of the box, with any non-essential features being optional.
watch-fs "echo File changed"
In this example, watch-fs will echo File changed
any time a file changes in the current directory. It will ignore further file changes for a short delay once the command finished. This is so that editors (and commands) that change multiple files don’t result in the command running several times.
Commands can use the name and path of the file that changed:
watch-fs "echo File '{name}' changed at path '{path}'"
A few arguments control optional features:
watch-fs --first --clear --verbose "rspec"
watch-fs -fcv "rspec"
--first
runs the command before waiting for changes.--clear
runsclear
before running the command, which keeps the terminal free of output from multiple runs of the command.--verbose
prints the command before running it, which is useful for separating the output or showing what was run when using--clear
.