talira

Ruby gem that watches files for changes

open sourceMITfree

Listen is a Ruby gem that watches directories and tells you which files were modified, added or removed. It uses OS-optimised adapters on macOS, Linux, BSD and Windows, falls back to polling where needed, watches several directories at once and ignores paths by regular expression. Its callback gets the lists of changed files, and options cover latency, forcing polling and adapter warnings. It lives in the same GitHub organisation as Guard.

Problems it solves

  • run code in Ruby when a file in a directory changes
  • watch a folder for added or deleted files from a Ruby script
  • reload my Ruby app when source files change

Features

  • Detects file modification, addition and removal
  • OS-optimised adapters for macOS, Linux, BSD and Windows
  • Polling fallback when no adapter works
  • Watch several directories at once
  • Ignore paths by regular expression

Limitations

  • Network and shared filesystems (NFS, Samba, sshfs, Vagrant shared folders) need polling.1
  • Symlinks are always followed, and symlinked directories pointing inside a watched directory aren't supported.1
  • Listeners don't notify across forked processes; each process must listen itself.1