-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.sh
executable file
·93 lines (77 loc) · 1.6 KB
/
base.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
set -euo pipefail
IFS=$'\n\t'
trap ctrl_c INT
trap signal_usr1 SIGUSR1
trap signal_usr2 SIGUSR2
function ctrl_c {
debug "Trapped CTRL-C"
callback_continue
}
function signal_usr1 {
debug "received USR1"
if [ ${status} -eq 0 ]; then
call_continue
sleep 30
debug "resuming"
call_suspend
fi
}
function signal_usr2 {
debug "received USR2"
call_continue
sleep 1
}
function call_suspend {
notify-send -u low -t 1000 "Suspending ${target}"
debug SUSPEND
callback_suspend
status=0
}
function call_continue {
notify-send -u low -t 1000 "Continue ${target}"
debug CONTINUE
callback_continue
status=1
}
function debug {
[ ${debug} -eq 1 ] && echo $(date) :: ${target} :: ${status} :: $1
return 0
}
usage() { echo "Usage: $0 [-d]" 1>&2; exit 1; }
debug=0
while getopts ":d" o; do
case "${o}" in
d)
debug=1
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
echo "####################"
echo "## CONTINUE"
declare -f callback_continue
echo
echo
echo "####################"
echo "## SUSPEND"
declare -f callback_suspend
while read -r line;
do
prog=$(echo $line | jq '.container.window_properties.class')
prog=${prog:1:-1}
change=$(echo $line | jq '.change')
change=${change:1:-1}
debug "${change} ${prog}"
if [ ${change} = "focus" ]; then
if [ "${prog}" = "${target}" ] && [ ${status} -eq 0 ]; then
call_continue
else
if [ ${status} -eq 1 ] && [ "${prog}" != "${target}" ]; then
call_suspend
fi
fi
fi
done < <(i3-msg -t subscribe -m '[ "window" ]')