bin/wakey.zsh: Add a new hack to tell me about long-running commands.
[profile] / bin / wakey.zsh
CommitLineData
9778630e
MW
1### -*-sh-*-
2
3## This idea shamelessly stolen from Jonathan Lange's `undistract-me'; see
4## <https://github.com/jml/undistract-me>.
5
6zmodload zsh/datetime
7
8__wakey_start=nil __wakey_cmd=
9: ${LONG_RUNNING_COMMAND_TIMEOUT=10}; export LONG_RUNNING_COMMAND_TIMEOUT
10
11__wakey_preexec () {
12 case $__wakey_start in
13 nil)
14 __wakey_start=$EPOCHREALTIME __wakey_cmd=$1
15 ;;
16 esac
17}
18
19__wakey_precmd () {
20 typeset icon head rc=$? cmd
21 typeset -F now=$EPOCHREALTIME
22
23 case $__wakey_start in
24 nil) ;;
25 *)
26 if (( now - __wakey_start >= LONG_RUNNING_COMMAND_TIMEOUT )); then
27 case $rc in
28 0) icon=trophy-gold head="Command completed" ;;
29 *) icon=dialog-warning head="Command FAILED (rc = $rc)" ;;
30 esac
31 cmd=${__wakey_cmd//&/&amp;}; cmd=${cmd//</&lt;}; cmd=${cmd//>/&gt;}
32 notify-send -c Wakey -i $icon -t 5000 $head $cmd
33 fi
34 __wakey_start=nil
35 ;;
36 esac
37}
38
39preexec_functions+=(__wakey_preexec)
40precmd_functions+=(__wakey_precmd)