Cameron Simpson avatar Cameron Simpson committed 3f779de

alert: log to daily ALERT log, support -title and -subtitle in order to support MacOSX terminal-notifier for notifications

Comments (0)

Files changed (1)

 : ${ALERTLOG:=$LOGDIR/alert-local}
 
 cmd=$0
-usage="Usage: $cmd [-c colour] [-G] {-|echo-args...]}"
+usage="Usage: $cmd [-c colour] [-G] [-s subtitle] [-t title] {-|echo-args...]}"
 
 colour=
 growl=
+tnotify=1
+title=
+subtitle=
 case "$OS" in
-  darwin)       growl=1 ;;
+  darwin)
+    growl=1
+    tnotify=1
+    ;;
 esac
-if flag GROWL_DISABLE
+if flag -w GROWL_DISABLE
 then  growl=
 fi
 
     -c) colour=$2; shift ;;
     -G) growl=1 ;;
     +G) growl= ;;
+    -t) title=$2; shift ;;
+    -s) subtitle=$2; shift ;;
     --) shift; break ;;
     -?*)echo "$cmd: unrecognised option: $1" >&2
         badopts=1
 
 xit=0
 
+message=$*
+[ -n "$subtitle" ] && set -- "$subtitle;" ${1+"$@"}
+[ -n "$title" ] && set -- "$title:" ${1+"$@"}
+
 exec >>"$ALERTLOG"
 
 if [ -n "$colour" ]
 else  echo "$*"
 fi || xit=1
 
+dlog "ALERT: $*"
+
 if [ $growl ]
 then
   # try growlnotify, otherwise hope /dev/tty is an iTerm
   growlnotify -m "$*" || echo $'\e]9;$*\a' >/dev/tty || xit=1
 fi
 
+if [ $tnotify ]
+then
+  terminal-notifier -title "$title" -subtitle "$subtitle" -message "$message"
+fi
+
 exit $xit
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.