From 6131a2527bbb25d0f007005d6bf5541095a1d9e2 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 20 Apr 2020 13:17:02 +0100 Subject: [PATCH] bin/wakey.zsh: Refactor the logic in `__wakey_precmd'. Split it into two sections: one to decide whether to report a notification, and a second to actually do it. The logic for the first stage is going to become more complicated, and this avoids having to have two copies of the notification code. --- bin/wakey.zsh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/wakey.zsh b/bin/wakey.zsh index 94638ca..41d518a 100644 --- a/bin/wakey.zsh +++ b/bin/wakey.zsh @@ -21,20 +21,25 @@ __wakey_preexec () { } __wakey_precmd () { - typeset icon head rc=$? cmd + typeset icon head rc=$? cmd suppress=nil typeset -F now=$EPOCHREALTIME case $__wakey_start in nil) ;; *) - if (( now - __wakey_start >= LONG_RUNNING_COMMAND_TIMEOUT )); then - 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 + if (( now - __wakey_start < LONG_RUNNING_COMMAND_TIMEOUT )); then + suppress=t 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 -- 2.11.0