1 ; Common utility functions used by scripts
4 (:require [babashka.process :as p]
5 [org.httpkit.client :as http]
6 [clojure.java.io :as io]
7 [clojure.string :refer [replace-first split-lines]])
8 (:import [java.nio.file Files FileSystems CopyOption StandardCopyOption]))
17 (defn extract-file-from-zip
18 [zip-file-name source destination]
19 (let [zip-file (io/file zip-file-name)
20 dest (io/file destination)
21 fs (FileSystems/newFileSystem (.toPath zip-file) nil)
22 file-in-zip (.getPath fs source (into-array String []))]
23 (Files/copy file-in-zip
25 (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING]))))
29 (if (.startsWith s "~")
30 (replace-first s "~" (System/getProperty "user.home"))
35 (io/copy (:body @(http/get url)) (io/file destination)))
38 "Make a function `f` behave like a UNIX shell command."
40 (when (= *file* (System/getProperty "babashka.file"))
41 (let [content (if (> (.available System/in) 0)
43 (first *command-line-args*))]
44 (doseq [arg (filter #(not= "" %) (split-lines content))]