#!/bin/zsh #dep:xprintidle pgrep chronic source ${$(realpath "$0"):h:h}/lib/common.zsh import-env awesome zparseopts -D -maxidle:=maxidle -in-chronic=chronic l:=logfile -logfile:=logfile if [[ $logfile ]]; then function debug() { echo "$(date --iso-8601=seconds) $*" >> $logfile } else function debug() {} fi if [[ ! $chronic ]]; then debug "Restarting with chronic" exec chronic $0 --in-chronic $ALLARGS fi if [[ $maxidle ]]; then maxidle=${maxidle[2]} debug "Checking idle time: $(xprintidle) / 1000 < $maxidle" if (($(xprintidle) / 1000 < $maxidle)); then debug "Checking pgrep $1: $(pgrep $1)" if ! pgrep $1; then debug "Running $*" eval "$*" exit $? fi fi else debug "Checking pgrep $1: $(pgrep $1)" if ! pgrep $1; then debug "Running $*" eval "$*" exit $? fi fi