Track file changes and automate script execution

Recently I came across an issue of "live" synchronization of my local files with a remote host. It was necessary to upload project files as they are modified.

Normally it would require thousands of rsync ... executions but thanks to entr everything was fully automatic.

entr is an Open Source project which helps to detect file changes and automates script rerunning. Example:

ag -l | entr ./sync.sh

Where:

  • ag -l lists all the files found by the Silver Searcher but it might be any other files listing command like ls *
  • sync.sh is a custom bash script for file syncing, in my case it was rsync based one-liner like rsync -avzh * my_vm:my_dir --exclude .git

Installation

Fortunately entr is available on Homebrew, so installation (for MacOS) is extremely easy:

brew install entr

Sources

http://entrproject.org/ - official entr website with much more examples and documentation