/
mousetrap
executable file
·66 lines (50 loc) · 1.2 KB
/
mousetrap
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
#!/usr/bin/env bash
# Mousetrap
#
program="$(realpath "$0")"
directory="$(dirname "$program")"
source "$directory/lib/Mousetrap.sh"
trap '$(Mousetrap.cleanup); exit' SIGHUP SIGINT SIGTERM
command=${1-}
mouse="${2-$(Mousetrap.current)}"
case $command in
# reset the mouse coordinates when the window recieves focus
reset)
Mousetrap.set "$(Mousetrap.activity)" "$(Mousetrap.caught)" "$(Mousetrap.set_at)"
;;
# bind a reset for whenever the window recieves focus
watch)
! Mousetrap.active && Mousetrap.watch "$mouse"
;;
info)
if ! Mousetrap.active; then
echo "Mousetrap not active"
exit 1
fi
echo "Tracking: $mouse"
echo "Process: $(Mousetrap.watcher)"
echo "Info: $(Mousetrap.info)"
;;
# turn the trap on or off
toggle)
if Mousetrap.active; then
Mousetrap.unset "$program";
else
if [ -z "$mouse" ]; then
echo "Please provide a class name of a window to watch"
exit 1
fi
Mousetrap.setup
$program watch "$mouse" &
fi
;;
check)
! Mousetrap.active && exit 1
Mousetrap.check
;;
# determine if mouse movement has occurred
*)
! Mousetrap.active && exit 1
Mousetrap.check
;;
esac