#!/bin/sh set -e . ${PREFIX:-~/.local}/lib/ejmejl/common unseen="$(assign Unseen-Sequence unseen)" 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; test "${folder#+}" != "$folder" || usage days_required="$1"; test "$days_required" -ge 0 2> /dev/null || usage; shift test -x "$(command -v "$1")" || usage if ps x -o tty,etime | grep '^\? *[0-9]\{1,\}-' > /dev/null; then # I am running something in an interactive shell, so do nothing. : else days_actual="$(ps x -o tty,etime | sed -n '/^\? *[0-9]\{1,\}-/ s/\? *\([0-9]\{1,\}\)-.*/\1/p' | sort -n | head -n1)" if test -n "$days_actual" && test "$days_actual" -ge "$days_required"; then # I am probably not logged in, so incdlvr and pack. ${PREFIX:-~/.local}/bin/incdlvr 2> /dev/null || : ${PREFIX:-~/.local}/bin/pack -q "$ncol" "$nrow" "$folder" "$unseen" | "$@" fi fi