Skip to content

Instantly share code, notes, and snippets.

@maxp
Created August 23, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxp/e374e71ff40e66bc68d09881d1a24526 to your computer and use it in GitHub Desktop.
Save maxp/e374e71ff40e66bc68d09881d1a24526 to your computer and use it in GitHub Desktop.
babashka maker library
(ns bmk.core
(:import
[java.time ZonedDateTime]
[java.time.format DateTimeFormatter])
(:require
[clojure.string :refer [split]]
[clojure.java.shell :refer [sh]]))
;=
(defn cmd [& cmd-args]
(let [{:keys [exit out]} (apply sh cmd-args)]
(if (= 0 exit)
(split out #"\n")
(throw (ex-info (str "cmd failed: " (first cmd-args) ) {:exit exit})))))
;;
(defn sh-c [args]
(let [{:keys [exit out]} (sh "sh" "-c" args)]
(if (= 0 exit)
(split out #"\n")
(throw (ex-info (str "sh-c failed: " args) {:exit exit})))))
;;
(defn die [msg]
(println msg)
(System/exit 1))
;;
(defn print-lines [lines]
(cond
(seq lines ) (doseq [l lines] (println l))
(not (nil? lines)) (println lines)
:else nil))
;;
(defn git-commit-hash []
(first (cmd "git" "rev-parse" "HEAD")))
;;
(defn iso-timestamp []
(.format (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ssX") (ZonedDateTime/now)))
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment