Skip to content

Instantly share code, notes, and snippets.

@lrenn
Created December 21, 2010 21:54
Show Gist options
  • Save lrenn/750683 to your computer and use it in GitHub Desktop.
Save lrenn/750683 to your computer and use it in GitHub Desktop.
(ns bake.notify
(:use [bake.core :only [os-name]]
[cake :only [*config* *current-task*]]
[clojure.java.shell :only [sh]]))
(def growl-format "growlnotify -s \"cake +task+\" -m \"+message+\"")
(def libnotify-format "notify-send \"cake +task+\" \"+message+\"")
(defn default-format []
(if (= "linux" (os-name))
libnotify-format
growl-format))
(defn cmd-seq [cmd]
(if (= "windows" (os-name))
["cmd" "/c" cmd]
["bash" "-c" cmd]))
(defn escape-quotes [m]
(clojure.string/replace m "\"" "\\\\\\\""))
(defn notify [message]
(print message)
(flush)
(when-not (= "true" (get *config* "notifications.disable"))
(let [cmd (or (get *config* "notifications.format")
(default-format))
cmd (clojure.string/replace cmd "+task+" (escape-quotes (str *current-task*)))
cmd (clojure.string/replace cmd "+message+" (escape-quotes (str message)))]
(try (apply sh (cmd-seq cmd))
(catch java.io.IOException e)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment