-
Notifications
You must be signed in to change notification settings - Fork 2
/
button
executable file
·51 lines (40 loc) · 1008 Bytes
/
button
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
#!/usr/bin/env bash
set -eu
declare -A animations
animations[busy]="b 1000"
animations[warning]="w 400"
animations[error]="e 400"
animations[noise]="n 1000"
animations[shimmer]="s 1000"
animations[rainbow]="r 1000"
animations[power]="p 700"
animations[hdd]="h 700"
animations[startup]="u 700"
animations[shutdown]="d 700"
usage() {
joinedkeys=$(echo ${!animations[@]} | sed 's/ /|/g')
echo "$0 [$joinedkeys|help]"
}
# must have a single parameter
if [ $# != 1 ]; then
usage
exit 1
fi
# user wants to print help
if [ $1 == "help" ]; then
usage
exit 0
fi
# animations array's key list must contain the parameter
if ! [[ " ${!animations[@]} " =~ " $1 " ]]; then
usage
exit 1
fi
devices=( $(ls -d /dev/protobutton* 2>/dev/null || true) )
if [ ${#devices[@]} -eq 0 ]; then
echo "no button found"
exit 1
fi
button=${devices[0]}
stty -F $button -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 9600
echo "${animations[$1]}" > "$button"