explaingit

emcrisostomo/fswatch

5,532C++Audience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A command-line tool that watches files and folders and prints a notification whenever something changes, useful for automating tasks like rerunning build scripts whenever source files are edited.

Mindmap

mindmap
  root((fswatch))
    What it does
      File watcher
      Change notifications
      Cross platform
    Tech Stack
      C++
      inotify Linux
      FSEvents macOS
    Use Cases
      Auto rebuild
      Auto reload
      Trigger scripts
    Extras
      libfswatch library
      Recursive watching
      Pattern filtering
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Automatically rerun a build or test script whenever a source file changes in your project folder.

USE CASE 2

Trigger a deployment or reload step whenever a config file is modified on a server.

USE CASE 3

Embed file-watching capability in your own C or Go application using the included libfswatch library.

Tech stack

C++CGo

Getting it running

Difficulty · easy Time to first run · 5min

Linux inotify backend does not detect changes made over a network or through certain low-level memory operations.

Open source and free to use in any project including commercial ones.

In plain English

fswatch is a command-line tool that watches files and folders on your computer and tells you when anything changes. You point it at a file or directory, and it will print a notification every time that file is created, modified, deleted, or renamed. This makes it useful for building automated workflows, like automatically rerunning a script whenever a source file changes. One of the tool's main strengths is that it runs on many operating systems, including macOS, Linux, Windows, and various BSD-based systems. Rather than using a single approach everywhere, it picks the method that works best on each platform. On macOS it uses Apple's built-in file system events system. On Linux it uses a kernel feature called inotify. On Windows it uses a Windows API call. There is also a fallback method that works anywhere, which checks for changes by polling the file system on a schedule. fswatch supports watching entire directory trees recursively, so you do not need to list every subfolder separately. You can also filter which files trigger a notification using text patterns, so you could watch only files ending in a certain extension while ignoring others. The format of the output is configurable, meaning you can pipe it into other tools in custom ways. The project also ships a companion library called libfswatch, which developers can include in their own C, C++, or Go programs if they want to add file-watching capabilities directly to an application rather than calling the command-line tool. Each underlying monitoring method has trade-offs. The Linux inotify approach, for example, does not track changes made over a network or through certain low-level memory operations. The BSD kqueue approach opens a file descriptor for every file being watched, so it can run into system limits when monitoring a very large number of files. The README covers these limitations in detail so you can choose the right backend for your situation.

Copy-paste prompts

Prompt 1
How do I use fswatch to watch a folder and automatically run a shell script whenever any .js file changes?
Prompt 2
Set up fswatch on macOS to monitor a directory and restart a Node.js server every time a file changes.
Prompt 3
How do I filter fswatch to only notify me about changes to files with a specific extension while ignoring everything else?
Prompt 4
Explain the difference between fswatch backends such as FSEvents, inotify, kqueue, and poll, and which one I should use on Linux.
Open on GitHub → Explain another repo

← emcrisostomo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.