#!/bin/sh -e
#
#    notify_osd: print notify-osd messages in screen's notification buffer
#    Copyright (C) 2010 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@canonical.com>
#             with help from Mathias Gug <mathias.gug@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

LOG="$HOME"/.cache/notify-osd.log
[ -z "$BYOBU_PREFIX" ] && BYOBU_PREFIX="/usr"

case "$1" in
	--short)
		exit 0
	;;
	--detail)
		cat "$LOG" || true
		exit 0
	;;
esac

# This line operates basically as a daemon, watching the notify-osd log file,
# processing new messages and sending them to screen
CMD="tail --pid $PPID -n 0 -F $LOG"
pkill -f "$CMD" || true
$CMD | $BYOBU_PREFIX/lib/byobu/.notify_osd "$PPID"
