3 ms·
With a proper Makefile, $ cd project $ inotifywait -m -e modify,close_write,move,move_self,create,delete,delete_self -r . | while read; do make; done
by philsnow 13y ago
With a proper Makefile,
$ cd project
$ inotifywait -m -e modify,close_write,move,move_self,create,delete,delete_self -r . | while read; do make; done
Every time any source is modified, renamed, created, etc, that will run 'make', rebuilding whatever output artifacts you need.
As long as you're careful about always re-fetching artifacts (like css files built from whatever css-sugar-y thing is hot this week) somehow, that should set you up nicely, and it generalizes to all kinds of workflows.
- jhh 13y agoThanks for making me aware of this. This is linux specific but something like this seems to be available on Mac OS X (https://github.com/alandipert/fswatch https://github.com/alandipert/fswatch). I don't quite understand where in your command you specify that make is executed? Could you expand on that.
- dota168 13y agowhile read; do make; done
- philsnow 13y agothat's spot on. the command "inotifywait -m -r . -e {some events}" recursively watches all inodes in the current directory (the "-r" and "." parts) for events in the {some events} list, and every time something happens (you save a file, create a new one, open a file, etc etc), inotifywait prints a line. The "-m" flag makes it print a line and keep watching. Without that, it's a one-shot (which can work like [0] but all the setting up and tearing down of inotify watches is expensive on a large project). [0] $ while inotifywait -e some,events -r . ; do make; done
- apinstein 13y ago+1 I got sick of not having a unified way of managing auto-rebuiding across the variety of tools I use (compass, coffescript, closure compiler, rake, etc) so I built something similar. I just wanted to say if * changes, run X, oh and by the way please debounce change events before running X. And the app needed to be easy for other devs to use it reliably and reproducibly. https://github.com/apinstein/watchngo https://github.com/apinstein/watchngo
- philsnow 13y agoAs I typed it I was thinking that debouncing change events would be nice; as I wrote the above, you'll get several events depending on what operations you're performing. It happens that subsequent invocations of 'make' will be blindingly fast because it will check inode timestamps (by default, you can force make to look deeper if you have Reasons) and because those inodes will still be cached "somewhere" in the kernel. So, debouncing isn't critical for this particular use case, but it would give me a warm fuzzy feeling.
- netghost 13y agoI wrote a little tool to do that, http://github.com/adamsanderson/when-files-change http://github.com/adamsanderson/when-files-change . For instance when-files-change -- make In general, it has the same underlying mechanism, but simpler to remember ;)
- poxrud 13y agoAnother option is using Grunt with the watch plugin.