{"id":23123506,"url":"https://github.com/knbr13/watcher","last_synced_at":"2025-09-04T09:46:55.845Z","repository":{"id":167707356,"uuid":"643329378","full_name":"knbr13/watcher","owner":"knbr13","description":"📁 watch file system events and respond by user-defined commands.","archived":false,"fork":false,"pushed_at":"2025-03-18T05:41:29.000Z","size":149,"stargazers_count":27,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-17T03:35:39.933Z","etag":null,"topics":["cli","events","filesystem","go","golang","watcher"],"latest_commit_sha":null,"homepage":"","language":"Go","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/knbr13.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-20T20:15:12.000Z","updated_at":"2025-05-11T06:11:05.000Z","dependencies_parsed_at":"2025-08-17T03:31:57.901Z","dependency_job_id":"62632c87-3791-4bc6-bb36-de73b618c00d","html_url":"https://github.com/knbr13/watcher","commit_stats":null,"previous_names":["abdullah-alaadine/code-editor","knbr13/code-editor","knbr13/watcher"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/knbr13/watcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knbr13%2Fwatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knbr13%2Fwatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knbr13%2Fwatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knbr13%2Fwatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knbr13","download_url":"https://codeload.github.com/knbr13/watcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knbr13%2Fwatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273587663,"owners_count":25132849,"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-09-04T02:00:08.968Z","response_time":61,"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":["cli","events","filesystem","go","golang","watcher"],"created_at":"2024-12-17T07:35:01.802Z","updated_at":"2025-09-04T09:46:55.778Z","avatar_url":"https://github.com/knbr13.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Watcher 👁️\n\n[![Go Version](https://img.shields.io/badge/go-1.24+-blue.svg)](https://golang.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA next-generation file system watcher that **automates your workflow** with surgical precision. \nReact to file changes like a pro!\n\n```text\n                 _      __ ______ / /_ _____ / /_   ___   _____\n                | | /| / // __  // __// ___// __ \\ / _ \\ / ___/\n                | |/ |/ // /_/ // /_ / /__ / / / //  __// /    \n                |__/|__/ \\____/ \\__/ \\___//_/ /_/ \\___//_/     \n                                                                \n```\n\n## Why Watcher? 🚀\n\nTired of manually restarting services or rebuilding projects? Watcher combines:\n\n✅ **Precision Targeting** - Globs/patterns for surgical reaction  \n⚡ **Workflow Chaining** - Parallel/sequential command execution  \n🔔 **Smart Notifications** - Success/failure hooks with rich context  \n\nPerfect for: Go devs • DevOps • Content creators • Data engineers\n\n## Features ✨\n\n- 🔍 **Event Types**: `write`|`create`|`remove`|`rename`|`chmod`|`common`\n- 🎯 **Glob Patterns**: `**/*.go` `!**/testdata/` `config/*.{yaml,yml}`\n- ⏱️ **Timeout Control**: Prevent hung commands from blocking your flow\n- 🌍 **Env Variables**: `$FILE` `$EVENT_TYPE` `$TIMESTAMP` [→ Full list](#environment-variables-)\n- 🧩 **Modular Rules**: Combine commands in parallel/sequence\n- 📡 **Notifications**: Webhooks, desktop alerts, custom scripts\n\n## Installation ⚡\n\n### From Source\n```bash\ngo install github.com/knbr13/watcher@latest\n```\n\n### Prebuilt Binaries\nDownload from [Releases](https://github.com/knbr13/watcher/releases)\n\n## Quick Start 🚀\n\n1. Create `watcher.yaml`:\n```yaml\n# Restart Go server on *.go changes\nwrite:\n  - pattern: \"**/*.go\"\n    commands: [\"pkill -SIGINT myapp\", \"go run .\"]\n    timeout: 30s\n    on_success: [\"notify-send 'Server reloaded!'\"]\n```\n\n2. Start watching:\n```bash\nwatcher --file watcher.yaml --recursive\n```\n\n## Configuration Guide 📋\n\n### Example Config\n```yaml\n# Global hooks\non_success: \"echo 'All systems go! 🚀'\"\non_failure: \"curl -X POST https://api.status.io/down\"\n\nwrite:\n  - pattern: \"src/**/*.js\"\n    commands:\n      - \"npm run lint\"\n      - \"npm run build\"\n    sequential: true  # Run commands in order\n    timeout: 1m       # Fail if build takes \u003e1 minute\n\ncreate:\n  - pattern: \"*.{jpg,png}\"\n    commands: [\"convert $FILE -resize 50% resized/$FILE_BASE\"]\n```\n\n### Environment Variables 🌍\n\n| Variable       | Description                      |\n|----------------|----------------------------------|\n| `$FILE`        | Full path to changed file        |\n| `$FILE_BASE`   | Filename only (e.g., `app.go`)   |\n| `$FILE_DIR`    | Parent directory of file         |\n| `$FILE_EXT`    | The extension of the file        |\n| `$EVENT_TYPE`  | Event type (`WRITE`, `CREATE`)   |\n| `$EVENT_TIME`  | RFC3339 formatted time           |\n| `$TIMESTAMP`   | Unix timestamp of event          |\n| `$PWD`         | Current working directory        |\n\n\n## Real-World Examples 🛠️\n\n### 1. File Sync\n```yaml\n# Sync new images to S3\ncreate:\n  - pattern: \"uploads/*.{jpg,png}\"\n    commands: [\"aws s3 cp $FILE s3://my-bucket/$FILE_BASE\"]\n```\n\n### 2. Secure Service Management\n```yaml\n# Restart NGINX when config changes (with privilege escalation)\nwrite:\n  - pattern: \"/etc/nginx/**/*.conf\"\n    commands: [\"sudo nginx -t\", \"sudo systemctl reload nginx\"]\n    timeout: 15s\n    on_failure: [\"logger -t watcher 'NGINX reload failed'\"]\n```\n\n### 3. Malware Scanning Pipeline\n```yaml\n# Scan new uploads with ClamAV → quarantine if infected\ncreate:\n  - pattern: \"/var/www/uploads/**/*.{exe,zip}\"\n    commands: \n      - \"clamscan $FILE --move=/quarantine\"\n      - \"curl -X POST http://localhost:8080/alert -d 'Infected: $FILE'\"\n    timeout: 2m\n```\n\n### 4. Database Backup Trigger\n```yaml\n# Create encrypted backup when DB schema changes\nwrite:\n  - pattern: \"schema/*.sql\"\n    commands:\n      - \"pg_dump -Fc mydb | age -p \u003e backup/$(date +%s).dump.age\"\n    on_success: [\"aws s3 cp backup/ s3://dbsnapshots/ --recursive\"]\n    on_failure: [\"pagerduty trigger 'Backup failed'\"]\n```\n\n### 5. CI/CD for Go Modules\n```yaml\n# Full pipeline on dependency changes\nwrite:\n  - pattern: \"**/go.mod\"\n    commands:\n      - \"go mod verify\"\n      - \"go mod tidy\"\n      - \"go test ./...\"\n    sequential: true\n    timeout: 5m\n```\n\n### 6. Real-Time Sync to Edge Servers\n```yaml\n# Sync changed assets to CDN nodes in parallel \nwrite:\n  - pattern: \"static/**/*.{css,js}\"\n    commands:\n      - \"rsync -az $FILE edge-node-1:/var/www/\"\n      - \"rsync -az $FILE edge-node-2:/var/www/\"\n      - \"rsync -az $FILE edge-node-3:/var/www/\"\n    on_success: [\"invalidate-cdn $FILE_ABS\"]\n```\n\n### 7. Smart Log Management\n```yaml\n# Rotate logs over 100MB\nwrite:\n  - pattern: \"/var/log/app/*.log\"\n    commands: \n      - \"[[ $(stat -c%s $FILE) -gt 100000000 ]] \u0026\u0026 gzip $FILE\"\n    on_success: [\"touch $FILE\"]  # Reset write time\n```\n\n### 8. Kubernetes Config Hot-Reload\n```yaml\n# Update configmap without pod restart\nwrite:\n  - pattern: \"k8s/configs/*.yaml\"\n    commands:\n      - \"kubectl create configmap app-config --from-file=$FILE -o yaml --dry-run=client | kubectl apply -f -\"\n    timeout: 30s\n```\n\n### 9. Dynamic Firewall Rules\n```yaml\n# Block IPs added to denylist\nwrite:\n  - pattern: \"/etc/iptables/denylist.txt\"\n    commands: [\"iptables-restore \u003c /etc/iptables/rules.v4\"]\n    on_failure: [\"fail2ban-client set sshd banip $(tail -1 $FILE)\"]\n```\n\n## Command Line Options ⚙️\n\n```text\n-f, --file        Configuration file (required)\n-p, --path        Directory to watch (default: current)\n-d, --debug       Enable debug-level logs\n-r, --recursive   Watch directories recursively\n```\n\n## Acknowledgements 💛\n\nBuilt with these awesome libraries:\n- [fsnotify](https://github.com/fsnotify/fsnotify) - File system notifications\n- [go-arg](https://github.com/alexflint/go-arg) - CLI argument parsing\n- [doublestar](https://github.com/bmatcuk/doublestar) - Glob pattern matching\n\n---\n\n**Watcher** © 2025 - MIT License | Crafted with ❤️ by [knbr13](https://github.com/knbr13)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknbr13%2Fwatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknbr13%2Fwatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknbr13%2Fwatcher/lists"}