Created
December 21, 2010 21:54
-
-
Save lrenn/750683 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
(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