From: Mark Wooding Date: Mon, 20 Apr 2020 00:22:44 +0000 (+0100) Subject: bin/wakey.zsh: Add a new hack to tell me about long-running commands. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/9778630e5d065536276ab5c9f8bc7c541af0f5e0 bin/wakey.zsh: Add a new hack to tell me about long-running commands. This idea was from Jonathan Lange's `undistract-me': see https://github.com/jml/undistract-me for the original for Bash. --- diff --git a/Makefile b/Makefile index 1d32b62..ecc3bb8 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ ELISP += dot-emacs dot-emacs_DEPS = make-regexp SCRIPTLINKS += emacsclient-hack movemail-hack sendmail-hack -SCRIPTLINKS += aspell-hack emerge-hack +SCRIPTLINKS += aspell-hack emerge-hack wakey.zsh %.elc: %.el $$(foreach e, $$($$*_DEPS), $$(DEP_$$e)) $(call v_tag,EMACS)if ! $(EMACS) >$*.build-log 2>&1 \ diff --git a/bin/wakey.zsh b/bin/wakey.zsh new file mode 100644 index 0000000..c5471f8 --- /dev/null +++ b/bin/wakey.zsh @@ -0,0 +1,40 @@ +### -*-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 + +__wakey_preexec () { + case $__wakey_start in + nil) + __wakey_start=$EPOCHREALTIME __wakey_cmd=$1 + ;; + esac +} + +__wakey_precmd () { + typeset icon head rc=$? cmd + 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 + fi + __wakey_start=nil + ;; + esac +} + +preexec_functions+=(__wakey_preexec) +precmd_functions+=(__wakey_precmd)