Skip to content

Instantly share code, notes, and snippets.

@Saikyun Saikyun/zig_watch.clj
Last active May 22, 2020

What would you like to do?
babashka command to watch a folder for changes to .zig-files
#!/usr/bin/env bb
(if *command-line-args*
(def in (str (first *command-line-args*)))
(println "Which bin to run?")
(def in (str *input*))))
(println "Watching" "*.zig" "->" (str "./" in))
(require '[babashka.pods :as pods])
(pods/load-pod "pod-babashka-filewatcher")
(require '[pod.babashka.filewatcher :as fw])
(def chan (fw/watch "." {:delay-ms 0}))
(require '[clojure.core.async :as async])
(loop []
(let [res (async/<!! chan)]
#_(prn res)
(when (and (#{"write" "create"} (:type res))
(str/ends-with? (:path res) ".zig"))
(println (str "\n>> Compiling " (:path res) "..."))
(let [{:keys [out err]} (shell/sh "zig" "build-exe" (str in ".zig"))]
(when (seq out)
(println out))
(when (seq err)
(println err)))
(let [{:keys [out err]} (shell/sh (str "./" in))]
(when (seq out)
(println out))
(when (seq err)
(println err))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.