Format all Clojure files using zprint
[babashka-scripts.git] / lib.clj
1 ; Common utility functions used by scripts
2
3 (import '[java.nio.file Files FileSystems CopyOption StandardCopyOption])
4
5 (defn extract-file-from-zip
6 [zip-file-name source destination]
7 (let [zip-file (io/file zip-file-name)
8 src (io/file source)
9 dest (io/file destination)
10 fs (FileSystems/newFileSystem (.toPath zip-file) nil)
11 file-in-zip (.getPath fs source (into-array String []))]
12 (Files/copy file-in-zip
13 (.toPath dest)
14 (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING]))))
15
16 (defn expand-home
17 [s]
18 (if (.startsWith s "~")
19 (clojure.string/replace-first s "~" (System/getProperty "user.home"))
20 s))