chiark / gitweb /
bin/wakey.zsh: Refactor the logic in `__wakey_precmd'.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 20 Apr 2020 12:17:02 +0000 (13:17 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 20 Apr 2020 12:24:52 +0000 (13:24 +0100)
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

index 94638caa84ebad8518ae2e252fb17671bc1fb99d..41d518a3cfe04687d6506f6080941f7366bf4160 100644 (file)
@@ -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//&/&amp;}; cmd=${cmd//</&lt;}; cmd=${cmd//>/&gt;}
-       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//&/&amp;}; cmd=${cmd//</&lt;}; cmd=${cmd//>/&gt;}
+         notify-send -c Wakey -i $icon -t 5000 $head $cmd
+      esac
       __wakey_start=nil
       ;;
   esac