### -*-sh-*- ## This idea shamelessly stolen from Jonathan Lange's `undistract-me'; see ## . zmodload zsh/datetime __wakey_start=nil __wakey_cmd= : ${LONG_RUNNING_COMMAND_TIMEOUT=10}; export LONG_RUNNING_COMMAND_TIMEOUT : ${IGNORE_WINDOW_CHECK=nil}; export IGNORE_WINDOW_CHECK : ${LONG_RUNNING_IGNORE_LIST=}; export LONG_RUNNING_IGNORE_LIST __wakey_preexec () { case $__wakey_start in nil) case $LONG_RUNNING_IGNORE_LIST in *" $1 "*) ;; *) __wakey_start=$EPOCHREALTIME __wakey_cmd=$1 ;; esac ;; esac } __wakey_precmd () { typeset icon head rc=$? cmd suppress=nil typeset -i 10 win i typeset -F now=$EPOCHREALTIME case $__wakey_start in nil) ;; *) if (( now - __wakey_start < LONG_RUNNING_COMMAND_TIMEOUT )); then suppress=t else case $IGNORE_WINDOW_CHECK in t) ;; *) win=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/^.*# //') if (( win == WINDOWID )); then suppress=t else for i in $(xwininfo -children -id $win | sed -n '/^ *[0-9]\+ child\(ren\)\?[.:]$/,$ { /^ *\(0x[0-9a-f]\+\) (.*$/s//\1/p }') do if (( i == WINDOWID )); then suppress=t; break; fi done fi esac fi case $suppress in t) ;; *) case $rc in 0) icon=trophy-gold head="Command completed" ;; *) icon=dialog-warning head="Command FAILED (rc = $rc)" ;; esac cmd=${__wakey_cmd//&/&}; cmd=${cmd///>} notify-send -c Wakey -i $icon -t 5000 $head $cmd esac __wakey_start=nil ;; esac } case ${DISPLAY-nil},${WINDOWID-nil} in nil,* | *,nil) ;; *) if whence notify-send >/dev/null 2>&1; then preexec_functions+=(__wakey_preexec) precmd_functions+=(__wakey_precmd) fi ;; esac