{"id":20051883,"url":"https://github.com/p-ranav/fswatch","last_synced_at":"2025-10-04T17:56:26.263Z","repository":{"id":59203091,"uuid":"202944389","full_name":"p-ranav/fswatch","owner":"p-ranav","description":"File/Directory Watcher for Modern C++","archived":false,"fork":false,"pushed_at":"2022-11-26T16:16:56.000Z","size":81,"stargazers_count":84,"open_issues_count":2,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-24T22:40:29.391Z","etag":null,"topics":["events","filesystem","inotify","mit-license","modern-cpp","single-header-lib","watcher"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p-ranav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-18T00:43:21.000Z","updated_at":"2025-05-14T16:43:36.000Z","dependencies_parsed_at":"2023-01-23T01:30:51.748Z","dependency_job_id":null,"html_url":"https://github.com/p-ranav/fswatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/p-ranav/fswatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Ffswatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Ffswatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Ffswatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Ffswatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p-ranav","download_url":"https://codeload.github.com/p-ranav/fswatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Ffswatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278350987,"owners_count":25972676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["events","filesystem","inotify","mit-license","modern-cpp","single-header-lib","watcher"],"created_at":"2024-11-13T12:07:29.449Z","updated_at":"2025-10-04T17:56:26.226Z","avatar_url":"https://github.com/p-ranav.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\r\n  \u003cimg height=\"80\" src=\"https://i.imgur.com/YGfomu0.png\" alt=\"fswatch\"/\u003e\r\n\u003c/p\u003e\r\n\r\n## Highlights\r\n\r\n* Single header file\r\n* Requires C++17 and `std::filesystem`\r\n* MIT License\r\n* For now, ONLY works in Linux - based on [inotify](http://man7.org/linux/man-pages/man7/inotify.7.html)\r\n\r\n## Quick Start\r\n\r\nSimply include fswatch.hpp and you're good to go. \r\n\r\n```cpp\r\n#include \u003cfswatch.hpp\u003e\r\n```\r\nTo start watching files, create an `fswatch` object and provide a variadic list of directories to watch. \r\n\r\nThe constructor takes variadic arguments - Simply provide a list of directories to watch. This watcher will observe your home directory, `/opt`, `/tmp` and the current working directory. \r\n\r\n```cpp\r\nauto watcher = fswatch(\"~\", \"/opt\", \"/tmp\", \".\");\r\n\r\ntry {\r\n  watcher.start();\r\n} catch (const std::runtime_error\u0026 error) {\r\n  std::cout \u003c\u003c error.what() \u003c\u003c std::endl;\r\n}\r\n```\r\n\r\n## Register callbacks to events\r\n\r\nTo add callbacks to events, use the `watcher.on(...)` method like so:\r\n\r\n```cpp\r\nwatcher.on(fswatch::Event::FILE_CREATED, [](auto \u0026event) {\r\n  std::cout \u003c\u003c \"File created: \" \u003c\u003c event.path \u003c\u003c std::endl;\r\n});\r\n```\r\n\r\nYou can register a single callback for multiple events like this:\r\n\r\n```cpp\r\nwatcher.on({ fswatch::Event::FILE_OPENED, fswatch::Event::FILE_CLOSED },\r\n  [](auto \u0026event) {\r\n    if (event.type == fswatch::Event::FILE_OPENED)\r\n      std::cout \u003c\u003c \"File opened: \" \u003c\u003c event.path \u003c\u003c std::endl;\r\n    else\r\n      std::cout \u003c\u003c \"File closed: \" \u003c\u003c event.path \u003c\u003c std::endl;\r\n});\r\n```\r\n\r\nHere are the list of events that fswatch can handle:\r\n\r\n### File Events\r\n\r\n| Event              | Description                                                   |\r\n|--------------------|---------------------------------------------------------------|\r\n| FILE_CREATED       | File created in watched directory                             |\r\n| FILE_OPENED        | File opened in watched directory                              |\r\n| FILE_MODIFIED      | File modified in watched directory (e.g., write, truncate)    |\r\n| FILE_CLOSED        | File closed in watched directory                              |\r\n| FILE_DELETED       | File deleted from watched directory                           |\r\n\r\n### Directory Events\r\n\r\n| Event              | Description                                                   |\r\n|--------------------|---------------------------------------------------------------|\r\n| DIR_CREATED        | Directory created in watched directory                        |\r\n| DIR_OPENED         | Directory opened in watched directory (e.g., when running ls) |\r\n| DIR_MODIFIED       | Directory modified in watched directory                       |\r\n| DIR_CLOSED         | Directory closed in watched directory                         |\r\n| DIR_DELETED        | Directory deleted from watched directory                      |\r\n\r\n## Todo\r\n\r\n1. Suppport Win32, FreeBSD, and OSX\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ranav%2Ffswatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp-ranav%2Ffswatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ranav%2Ffswatch/lists"}