Skip to content

Instantly share code, notes, and snippets.

@minimal
Created September 20, 2016 15:28
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 minimal/61f11794561e3dca1076bacb9189e051 to your computer and use it in GitHub Desktop.
Save minimal/61f11794561e3dca1076bacb9189e051 to your computer and use it in GitHub Desktop.
(defmacro with-err-str
[& body]
`(let [s# (new java.io.StringWriter)]
(binding [*err* s#]
~@body
(str s#))))
(defn get-stack-trace-str
[e]
(with-err-str (clojure.repl/pst e)))
(require '[clojure.java.shell :refer [sh]])
(defn notify [title msg]
(sh "terminal-notifier" "-title" title "-message" msg "-sound" "default"))
(defmacro do-with-notif
"Eval body and call terminal-notifier with the result or exception"
[body]
`(time (try (let [res# ~body]
(notify "Success" (str res#))
res#)
(catch Exception e#
(let [err-str# (get-stack-trace-str e#)]
(notify "Failure" err-str#)
(throw e#))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment