bin/wakey.zsh: Delete the type setting.
[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
9778630e
MW
6__wakey_start=nil __wakey_cmd=
7: ${LONG_RUNNING_COMMAND_TIMEOUT=10}; export LONG_RUNNING_COMMAND_TIMEOUT
132a9791 8: ${IGNORE_WINDOW_CHECK=nil}; export IGNORE_WINDOW_CHECK
aeba0b89 9: ${LONG_RUNNING_IGNORE_LIST=}; export LONG_RUNNING_IGNORE_LIST
9778630e
MW
10
11__wakey_preexec () {
12 case $__wakey_start in
13 nil)
0621c557 14 case " $LONG_RUNNING_IGNORE_LIST " in
aeba0b89 15 *" $1 "*) ;;
1bea7f5c 16 *) __wakey_start=$SECONDS __wakey_cmd=$1 ;;
aeba0b89 17 esac
9778630e
MW
18 ;;
19 esac
20}
21
22__wakey_precmd () {
bb834f36 23 local icon head rc=$? cmd suppress=nil win i now=$SECONDS
9778630e
MW
24
25 case $__wakey_start in
26 nil) ;;
27 *)
6131a252
MW
28 if (( now - __wakey_start < LONG_RUNNING_COMMAND_TIMEOUT )); then
29 suppress=t
132a9791
MW
30 else
31 case $IGNORE_WINDOW_CHECK in
32 t) ;;
33 *)
34 win=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/^.*# //')
35 if (( win == WINDOWID )); then
36 suppress=t
37 else
41ca057f 38 for i in $(xwininfo -tree -id $win |
132a9791
MW
39 sed -n '/^ *[0-9]\+ child\(ren\)\?[.:]$/,$ {
40 /^ *\(0x[0-9a-f]\+\) (.*$/s//\1/p
41 }')
42 do
3c7d194d 43 if (( i == WINDOWID )); then suppress=t; break; fi
132a9791
MW
44 done
45 fi
46 esac
9778630e 47 fi
6131a252
MW
48 case $suppress in
49 t) ;;
50 *)
51 case $rc in
52 0) icon=trophy-gold head="Command completed" ;;
53 *) icon=dialog-warning head="Command FAILED (rc = $rc)" ;;
54 esac
55 cmd=${__wakey_cmd//&/&amp;}; cmd=${cmd//</&lt;}; cmd=${cmd//>/&gt;}
56 notify-send -c Wakey -i $icon -t 5000 $head $cmd
57 esac
9778630e
MW
58 __wakey_start=nil
59 ;;
60 esac
61}
62
a0611691
MW
63case ${DISPLAY-nil},${WINDOWID-nil} in
64 nil,* | *,nil) ;;
0b69235c
MW
65 *)
66 if whence notify-send >/dev/null 2>&1; then
67 preexec_functions+=(__wakey_preexec)
68 precmd_functions+=(__wakey_precmd)
69 fi
70 ;;
71esac