开发者

Program to re-run, eg, `make` when files are modified?

Is there a program that will aut开发者_运维技巧omatically re-run, eg, make, when files are modified?

For example, when I'm writing sphinx documentation, it would be nice if make html was run automatically each time I edit any relevant files.


For simple things, rerun could be a good fit: http://pypi.python.org/pypi/rerun

"Command-line executable Python script to re-run the given command every time files are modified in the current directory or its subdirectories."

It requires a Python interpreter, but does not care if your command or files are written in Python.

Usage

rerun [--help|-h] [--verbose|-v] [--ignore|-i=<file>] [--version] <command>
Where:

<command>           Command to execute
--help|-h           Show this help message and exit.
--ignore|-i=<file>  File or directory to ignore. Any directories of the
                    given name (and their subdirs) are excluded from the
                    search for changed files. Any modification to files of
                    the given name are ignored. The given value is
                    compared to basenames, so for example, "--ignore=def"
                    will skip the contents of directory "./abc/def/" and
                    will ignore file "./ghi/def". Can be specified multiple
                    times.
--verbose|-v        Display the names of changed files before the command
                    output.
--version           Show version number and exit.


In Linux, you can use this command line:

while true; do inotifywait -e close_write  *.py; make; done

Uses standard system command inotifywait, if not available, install with something like:

sudo apt install inotify-tools


Well, since make will not do anything if nothing has changed, how about

while true; do sleep 60; make html; done

or the equivalent in your shell of choice? I don't think the usual file system layers are event-driven in such a way that they will you notify you of file changes without doing some similar themselves, but it's possibly DBUS can do that sort of stuff.


You could use inotifywait in a loop: https://github.com/rvoicilas/inotify-tools/wiki/#info


As per answer https://stackoverflow.com/a/22907316/71522 watchman seems to work very well:

 $ watchman-make -p '*.c' 'Makefile' -t all

Will re-run make all each time any *.c or Makefile file changes.

It can be installed with:

$ brew install watchman


You could use incron: http://inotify.aiken.cz/?section=incron&page=about&lang=en


This question was also asked here: https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes/

You could try reflex

# Rerun make whenever a .c file changes
reflex -r '\.c$' make
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜