我目前的解决方案是使用python库看门狗和bash片段(originally taken from here)。
watchmedo shell-command client/js/src/templates/ proto/ --recursive \
--patterns="*.soy;*.proto" \
--command="echo \"WATCHMEDO file changed - rebuilding\"; make genfiles;"
基本上我正在观看一些模板文件,然后在其中一个模板文件发生变化时自动运行make genfiles。
我想知道是否有办法在纯粹的bash中做到这一点?我宁愿不让所有开发人员都依赖Python库。
我在OSX上。
答案 0 :(得分:5)
#!/bin/bash
watched_files=$@ # pass watched files as cmd line arguments
if [ -z "$watched_files" ]; then
echo "Nothing to watch, abort"
exit
else
echo "watching: $watched_files"
fi
previous_checksum="dummy"
while [ 1 ]; do
checksum=$(md5 $watched_files | md5) # I use Mac so I have `md5`, in linux it's `md5sum`
if [ "$checksum" != "$previous_checksum" ]; then
echo "None shall pass!" # do your stuff here
fi
previous_checksum="$checksum"
sleep 1
done
答案 1 :(得分:1)
这是一个不错的cli FAM客户端:http://fileschanged.sourceforge.net/