#!/bin/ksh
#
# $Revision: 1.13+5 $ $Date: 2012-07-26 17:09:06-04 $
# $Source: /home/vogelke/bin/RCS/xnote,v $
# $Host: sys7.com $
# $UUID: 0ca33a57-852d-381a-9901-9b517f4c2c09 $
#
#<xnote: show a short message or email subject in a popup.

export PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
export USER=vogelke
tag="${0##*/}"

logmsg () {
    logger -t $tag -p local6.info "$@"
}

case "$DISPLAY" in
    "") export DISPLAY="unix:0.0" ;;
    *)  ;;
esac

test -f "$HOME/.noxnote" && exit 0

# Send message if running from cron or under X-Windows.

EMAIL=0
case "$#" in
    0)  EMAIL=1; msg="$(cat -)" ;;
    *)  str=${1+"$@"} ;;
esac

case "${EMAIL}${CRON}${WINDOWID}" in
    "")  exit 0 ;;     # not an X-session
    *)   ;;
esac

# If email and the message body is empty, look for the subject.
# If no subject, just print whatever came in via stdin.

case "$EMAIL" in
    0)  ;;

    1)  str=$(echo "$msg" | sed -n -e '/^$/,$p')
        case "$str" in
            "") str=$(echo "$msg" | grep 'Subject:' |
                sed -e 's/Subject://g') ;;
            *)  ;;
        esac

        case "$str" in
            "") str="$msg" ;;
            *)  ;;
        esac
        ;;
esac

case "$str" in
    "")  exit 0 ;;     # no message, so bail.
    *)   ;;
esac

# Print the date and each separate line from the message.
# This window size will handle about 42 characters per line.
# Each separate input line will show up as a separate line in the note.

set X $(date)
today="$4 $3 $5"
xalarm -name xmemo -time +0 -geometry +20-60 -nowarn "$today
$str"

exit 0
