pod-babashka-fswatcher

command module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

README

pod-babashka-fswatcher

A babashka pod for watching files.

Implemented using the Go fsnotify library.

Status

Experimental.

Usage

Load the pod:

(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/fswatcher "0.0.3")

(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.

Usage in bb.edn

In babashka 0.8.0 it is possible to specify pods in bb.edn:

{:pods {org.babashka/fswatcher {:version "0.0.3"}}
 :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)))}}}
Watch recursively

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})

Build

Requirements
  • Go 1.18+ should be installed.
  • Clone this repo.
  • Run go build -o pod-babashka-fswatcher main.go to compile the binary.

License

Copyright © 2020 Rahul De and Michiel Borkent

License: BSD 3-Clause

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL