2012-03-12 29 views
0

我正在使用這個Guardfile來監視.cpp和.h文件,並且如果有任何更改,就會觸發make。在該目錄中Guardfile是偉大的,只要所有文件都有效。使用紅寶石守護gem來監視C++文件

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

我想有Guardfile在我的項目樹的根目錄下,並監視每個h和.cpp文件子目錄。是否有可能通過更改正則表達式來實現,還是必須在每個子目錄中都有一個Guardfile?

(不知道爲什麼格式不正確地通過去)

回答

1

你應該能夠這樣通過正則表達式。試試這個:

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

這應該與擴展的.cpp或.H您的應用程序的根目錄下的任何目錄匹配的文件。如果你想專注於一個子目錄嘗試^dir/sub/.+\.(h|cpp)$

+0

感謝子目錄評論。 – user566245 2013-09-18 15:37:01

3

您必須安裝以下兩種寶石:

guard 
guard-shell 

在目錄中創建一個Guardfile,你想要觀看的文件

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

重要的是,實際的shell命令(這裏:使得測試)必須包裝在「

然後運行:> guard