A babashka pod for watching files.
Implemented using the Go fsnotify library.
Experimental.
Load the pod:
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/fswatcher "0.0.5")
(require '[pod.babashka.fswatcher :as fw])
Watchers can be created with fw/watch
:
(def watcher (fw/watch "src" (fn [event] (prn event))))
You can create multiple watchers that run concurrently, even on the same directory.
The watch
function returns a value which can be passed to unwatch
which
stops and cleans up the watcher:
(fw/unwatch watcher)
See test/script.clj for an example test script.
In babashka 0.8.0 it is possible to specify pods in bb.edn
:
{:pods {org.babashka/fswatcher {:version "0.0.5"}}
:tasks {watch {:requires ([pod.babashka.fswatcher :as fw])
:task (do (fw/watch "project.clj"
(fn [event]
(when (#{:write :write|chmod} (:type event))
(println "hello!"))))
(deref (promise)))}}}
By default watchers do not watch recursively. Pass {:recursive true}
in the
options map to enable it.
(fw/watch "src" (fn [event] (prn event)) {:recursive true})
- Go 1.18+ should be installed.
- Clone this repo.
- Run
go build -o pod-babashka-fswatcher main.go
to compile the binary.
Copyright © 2020 Rahul De and Michiel Borkent
License: BSD 3-Clause