]> njoseph.me Git - babashka-scripts.git/blobdiff - lib.clj
utils: Add run-seq
[babashka-scripts.git] / lib.clj
diff --git a/lib.clj b/lib.clj
index 1f88070ba456a7b9e516567a17180a9c3a8cf26c..fb67137a1fb0045a221222a63431e74c99c2fe88 100644 (file)
--- a/lib.clj
+++ b/lib.clj
@@ -4,7 +4,7 @@
   (:require [babashka.process :as p]
             [org.httpkit.client :as http]
             [clojure.java.io :as io]
-            [clojure.string :refer [replace-first]])
+            [clojure.string :refer [replace-first split-lines]])
   (:import [java.nio.file Files FileSystems CopyOption StandardCopyOption]))
 
 (defn run-cmd
 (defn download-binary
   [url destination]
   (io/copy (:body @(http/get url)) (io/file destination)))
+
+(defn unixify
+  "Make a function `f` behave like a UNIX shell command."
+  [f]
+  (when (= *file* (System/getProperty "babashka.file"))
+    (let [content (if (> (.available System/in) 0)
+                    (slurp *in*)
+                    (first *command-line-args*))]
+      (doseq [arg (filter #(not= "" %) (split-lines content))]
+        (f arg)))))