#!/bin/sh -

RSHCMD='ssh -q -x -n'

allhosts="$MAILHOST $MAILHOST3 $MAILHOST2"
allhosts="`echo $allhosts | sed 's/localhost//g'`"
termenvx="setenv RH '$RH'; "
termenvc="setenv TERM '$TERM'; soenvls; "
piconsin='/l/picons/ftp/incoming'
opost='/u/oracle/post'

# work - list hosts' various working, incoming, and pending files
# Steve Kinzler, steve@kinzler.com, Dec 13
# https://kinzler.com/me/home.html#homedir

case "$1" in
LOOP)	shift
	while :; do clear; "$0" ${1+"$@"}; /bin/echo -n ///; read x; done
	exit;;
esac

term=; termenv="$termenvx"; termc=; termls='--color=auto'
case "$1" in
-h)	echo "usage: $0 [ LOOP ] [ -t ] [ ALL | host ... ]" 1>&2; exit 1;;
-t)	shift; termc='-f';;
esac
test -n "$termc" -o -t 1 && { term='-t'; termenv="$termenv$termenvc";
			      termls='--color=always'; }

case "$1" in
ALL)	set x $allhosts; shift;;
esac

case "$#" in
0)	;;
*)	for host
	do
		echo "========== $host ==========" | color $termc on_blue
		${RSHCMD-rsh} "$host" csh -c "\"$termenv'$0' $term\""
	done
	exit;;
esac

###############################################################################

grep '^From ' "$MAIL" 2> /dev/null		   | color $termc green

case "$RH" in
alembic*)	dhopts='-s -t -o';;
*)		dhopts='-p -s -t -o';;
esac
dailyh $dhopts					   | color $termc red

(cd; find -H work -mindepth 1 -maxdepth 2 \
	\! \( -regex '[^/]*/[^/]*' -type d \) -exec ls -1di $termls {} +) |
     sed 's/[0-9][0-9]*[ 	]/	/'	   | color $termc yellow /todo

case "${HOST-${HOSTNAME-`(hostname) 2> /dev/null`}}" in
"$MAILHOST")	find "$piconsin" -mindepth 2 -maxdepth 2 -print | sort
		find "$opost"/post* "$opost"/recd* "$opost"/vote* \! -empty \
			-print 2> /dev/null | sort;;
esac						   | color $termc magenta

todo -a -D					   | color $termc 'bold black'

atls						   | color $termc cyan

echo ''
