X-Git-Url: https://njoseph.me/gitweb/babashka-scripts.git/blobdiff_plain/00a9627659403ac2a910f8753cc2b1510384d6c3..76cc62f08f19febed3fe9025a8315c3486fcd214:/lib.clj diff --git a/lib.clj b/lib.clj index 1f88070..fb67137 100644 --- 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 @@ -33,3 +33,13 @@ (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)))))