Created
September 20, 2016 15:28
-
-
Save minimal/61f11794561e3dca1076bacb9189e051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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