]> njoseph.me Git - babashka-scripts.git/blob - lib.clj
e4616afe687eb257edbe3112b5fc749eb9f69562
[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 (.toPath dest)
13 (into-array CopyOption [StandardCopyOption/REPLACE_EXISTING]))))
14
15 (defn expand-home [s]
16 (if (.startsWith s "~")
17 (clojure.string/replace-first s "~" (System/getProperty "user.home"))
18 s))