#!/bin/sh set -e . ${PREFIX:-~/.local}/lib/ejmejl/common unscheduled="$(assign Inbox inbox)" usage() { echo 'usage: loop ncol nrow +folder days-of-inactivity command ...' >&2 exit 2 } test $# -gt 4 || usage ncol="$1"; shift nrow="$1"; shift folder="$1"; shift days="$1"; test "$days" -gt 0 2> /dev/null || usage; shift test -x "$(command -v "$1")" || usage if test "$(who | grep "^$LOGNAME"| wc -l)" -gt 1; then exit # I am logged in to an interactive shell, so do nothing. elif w -h -s "$LOGNAME" | sed "s/ */ /g" | cut -d\ -f4|grep '[sm]' > /dev/null; then exit # I ran a command interactively in the last hour, so do nothing. elif test -n "$(last --since "-${days}days" --limit 1 "$LOGNAME" | head -n1)"; then exit # I have logged in recently, so do nothing. This also double-checks the first condition. else # After triple-checking that I am probably not logged in, incdlvr and pack. ${PREFIX:-~/.local}/bin/incdlvr 2> /dev/null || : ${PREFIX:-~/.local}/bin/pack "$ncol" "$nrow" "+$unscheduled" "$unseen" | "$@" fi