42 lines
		
	
	
	
		
			839 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			839 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/zsh
 | |
| #dep:xprintidle pgrep chronic
 | |
| 
 | |
| source ${$(realpath "$0"):h:h}/lib/common.zsh
 | |
| import-env awesome
 | |
| ALLARGS=("$@")
 | |
| 
 | |
| zparseopts -D -maxidle:=maxidle -in-chronic=chronic l:=logfile -logfile:=logfile
 | |
| 
 | |
| if [[ $logfile ]]; then
 | |
| 	function debug() {
 | |
| 		echo "$(date --iso-8601=seconds) $*" >> ${logfile[2]}
 | |
| 	}
 | |
| else
 | |
| 	function debug() {}
 | |
| fi
 | |
| 
 | |
| if [[ ! $chronic ]]; then
 | |
| 	debug "Restarting with chronic"
 | |
| 	exec chronic $0 --in-chronic "${ALLARGS[@]}"
 | |
| fi
 | |
| 
 | |
| if [[ $maxidle ]]; then
 | |
| 	idle=$(xprintidle)
 | |
| 	maxidle=${maxidle[2]}
 | |
| 	debug "Checking idle time: $idle / 1000 < $maxidle"
 | |
| 	if (($idle / 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
 | 
