guard/guard-process

Copying doesn't work

Closed this issue · 3 comments

I'm trying to run guard-process to copy a folder somewhere else every time a file in that folder is changed. I tried this:

guard 'process', name: 'Copy', command: 'rm -rf /another/folder && cp -r folder /another/folder' do
  watch %r(^folder/(.+))
end

But it doesn't work, the folder is not copied, even though it runs in the Guard console every time I save a file in folder.
What am I doing wrong?

You can't specify multiple shell commands with guard-process because of the way it launches its processes, if you want to combine several shell commands in one command you will need to write a little shell script and use that as your command.

Another solution that would work for your use case is to use rsync instead of cp to mirror the source directory to the destination directory, you could use something like this which should achieve the same result as what you are trying to do:

guard 'process', name: 'Copy', command: 'rsync -rv --delete source/ /path/to/destination' do
  watch %r(^source/(.+))
end

Great, thanks!

You're welcome! :)