{"id":21619066,"url":"https://github.com/bannzai/ocha","last_synced_at":"2025-04-11T08:43:03.018Z","repository":{"id":63452149,"uuid":"173259950","full_name":"bannzai/Ocha","owner":"bannzai","description":"Listen to the file system change notifications and raises events when a directory, or file in a directory, changes. 🍵","archived":false,"fork":false,"pushed_at":"2019-06-25T23:23:14.000Z","size":2795,"stargazers_count":130,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-06T05:00:02.474Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","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/bannzai.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-03-01T07:59:08.000Z","updated_at":"2025-03-23T03:37:21.000Z","dependencies_parsed_at":"2022-11-19T06:45:35.129Z","dependency_job_id":null,"html_url":"https://github.com/bannzai/Ocha","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FOcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FOcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FOcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FOcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bannzai","download_url":"https://codeload.github.com/bannzai/Ocha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248362528,"owners_count":21091147,"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","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":[],"created_at":"2024-11-24T23:07:48.530Z","updated_at":"2025-04-11T08:43:02.998Z","avatar_url":"https://github.com/bannzai.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Ocha](logo/ocha_logo.png)](logo/ocha_logo.png)\n\n[![swift4.2](https://img.shields.io/badge/language-swift4.2-blue.svg?style=flat)](https://developer.apple.com/swift)\n[![Platform](https://img.shields.io/badge/platform-macOS-green.svg)](https://img.shields.io/badge/platform-macOS-green.svg)\n[![License](http://img.shields.io/badge/license-MIT-000000.svg?style=)](https://github.com/bannzai/Ocha/blob/master/LICENSE)\n\n# Ocha\n`Ocha` can be listen to the file system change notifications and raises events when a directory, or file in a directory, changes.\n\nOcha means Tea🍵 in Japan.\n\n## Usage\nTo use Ocha, first create a `Watcher` instance with file paths you want to watch.\n\n```swift\nlet watcher = Watcher(paths: [pathString])\n```\n\nAnd you can call for `Watcher.start(_:)` method when it start to watch file events.\nWhen file removed, you get callback with removed file path infomations.\n\n```swift\nwatcher.start { (events) in ... }\n```\n\n## Example\n\nThe following example execute `git add \u003c\u003c REMOVED_FILE_PATH \u003e\u003e` and `git commit -m \u003c\u003c REMOVED_FILE_PATH \u003e\u003e` to watch the file path, when it removed.\n\n```swift\nimport Foundation\nimport Ocha\nimport SwiftShell\nimport PathKit\n\nlet path = Path(\n    #file.components(separatedBy: \"/\")\n        .dropLast() // main.swift\n        .dropLast() // GitCommitExample\n        .dropLast() // Sources\n        .joined(separator: \"/\")\n)\nlet pathString = path.absolute().string\nmain.currentdirectory = pathString\n\nlet watcher = Watcher(paths: [pathString])\nwatcher.start { (events) in\n    let removedEventPaths = events\n        .filter { $0.flag.contains(.removedFile) }\n        .map { $0.path }\n    removedEventPaths.forEach { path in\n        main.run(bash: \"git add \\(path)\")\n        main.run(bash: \"git commit -m \\\"Delete file \\(path)\\\"\")\n    }\n}\n\nRunLoop.current.run()\n```\n\nIf you execute this swift code, you can confirm removed file git log. `$ git log -1` \n\n## Try it easily\n\nYou can easily try Ocha by editing the `Playground` target.\n\n1. Clone this repository with git or Download sources.\n2. Open `./Sources/Playground/main.swift` .\n3. Add monitored paths and processes.\n4. Run `swift run Playground` on Terminal.\n\n\n## LICENSE\n[Ocha](https://github.com/bannzai/Ocha/) is released under the MIT license. See [LICENSE](https://github.com/bannzai/Ocha/blob/master/LICENSE.txt) for details.\n\nHeader logo is released [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/deed) license. Original design by [noainoue](https://github.com/noainoue).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Focha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbannzai%2Focha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Focha/lists"}