Skip to content

Instantly share code, notes, and snippets.

@saikyun
Last active April 8, 2021 09:40
Show Gist options
  • Save saikyun/7573a9fcaa2499942e48b4ea6cfc116a to your computer and use it in GitHub Desktop.
Save saikyun/7573a9fcaa2499942e48b4ea6cfc116a to your computer and use it in GitHub Desktop.
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*)))
(do
(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))))
(recur)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment