我正在尝试让jsdoc在我保存javascript文件时自动生成。我有一个可以工作的脚本,它存储文件的最后更新时间(当前是硬编码的),并与该文件的当前时间戳进行比较。我在一个while循环中运行它,该循环一直运行到按下CTRL-C,并插入0.1秒的休眠以停止消耗处理器。
这是工作脚本:
while :
do
if [ $(( lastTime )) -ne `stat -f %m -t %s javascript.js` ]
then
lastTime=`stat -f %m -t %s javascript.js`
# custom jsdoc generating script
jsdoc javascript.js
echo +++ Run: `date` +++
fi
# stops while loop from consuming a lot of resources
# and making my fan whirr like he wants the computer to take off
sleep .1
done我知道有一种更好的方法--但不是那种方法。感谢您的帮助。
编辑:安装了inotify-tools的linux机器的更新应该可以工作
#!/bin/bash
# with inotify-tools installed...
# only watches first parameter for modification
while inotifywait -e modify $1; do
echo
echo +++ Building JSDocs +++
jsdoc $@
echo +++ Last run: `date` +++
done但是,我希望它在Linux和OSX shell上都能工作,所以我可以在这两种环境中使用
发布于 2011-08-06 05:44:17
有一个名为INotify的linux内核特性,它监视文件系统是否有任何变化。它被公开为许多系统API。
对于脚本,有一个名为inotify-tools的包,它允许脚本访问通知系统。
https://stackoverflow.com/questions/6962913
复制相似问题