0

I'm using this Guardfile to watch .cpp and .h files and fire off make if anything changes. Works great as long as all files are in the directory the Guardfile is in.

guard 'shell' do
    watch(%r{^\w*\.(h|cpp)$}) do
        `make test` 
    end
end

I'd like to have the Guardfile in the root directory of my project tree and monitor the .h and .cpp files in each subdirectory. Is it possible to do that by changing the regex, or do I have to have a Guardfile in each subdirectory?

(Not sure why the formatting doesn't go through correctly)

4

2 回答 2

3

您必须安装以下两个 gem:

guard
guard-shell

在要查看文件的目录中创建一个Guardfile

guard 'shell' do 
  watch(%r{^.+\.(h|hpp|cpp)$}) do 
    `make test`
  end 
end

重要的是,实际的 shell 命令(这里:make test)必须包含在 ` `

然后运行:> guard

于 2012-03-31T18:00:43.517 回答
2

你应该可以通过正则表达式来做到这一点。尝试这个:

guard 'shell' do 
  watch(%r{^.+\.(h|cpp)$}) do 
    make test 
  end 
end

这应该与应用程序根目录下的任何目录中的文件匹配,扩展名为 .cpp 或 .h。如果您想专注于子目录,请尝试^dir/sub/.+\.(h|cpp)$

于 2012-03-14T12:46:28.593 回答