scripts/misc/cronhelp

43 lines
875 B
Plaintext
Raw Normal View History

2023-03-02 12:20:22 +00:00
#!/bin/zsh
#dep:xprintidle pgrep chronic
ALLARGS=("$@")
WINDOW_MANAGER=awesome
WM_PID=$(pgrep WINDOW_MANAGER | head -n 1)
export "${(@ps:\000:)$(</proc/${WM_PID}/environ)}"
2023-03-02 12:20:22 +00:00
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
2023-03-02 12:20:22 +00:00
if [[ ! $chronic ]]; then
debug "Restarting with chronic"
2023-03-02 12:20:22 +00:00
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 $*"
2023-03-02 12:20:22 +00:00
eval "$*"
exit $?
fi
fi