0

I would like to monitor directory for change and if any file in that directory changes then I would like to build software. How can I do it with a shell "oneliner" ?

I was trying some variations of

watch "if [ find _source -mmin -1 ]; then make; fi"

but it's not correct syntax.

4

2 回答 2

1

正如其他人建议的那样,使用inotifywait(来自inotify-toolsUbuntu上的包):

while inotifywait -qqre modify,create,delete,move _source;do make;done

这种方法的问题是在制作过程中的修改不会被检测到。要解决这个问题,您可以运行两个进程;第一个:

while inotifywait -qqre modify,create,delete,move _source;do touch trigger;done

还有一个:

while inotifywait -qqre create trigger
do while [ -f trigger ]
   do rm trigger; make
   done
done
于 2013-08-20T22:35:13.127 回答
0

好的,所以我最终做的是

while inotifywait --exclude "\.(swp|~)"  -qqre modify _source; do make ; done

交换文件有问题,因为每次我用 vim 打开文件时都会触发构建,我希望它只在文件更改后触发。

还有一个问题:有谁知道我是否可以指定正则表达式来匹配我想触发事件的文件?例如*.cpp

于 2013-08-21T08:26:01.403 回答