-
Notifications
You must be signed in to change notification settings - Fork 1
/
blind.tool
executable file
·95 lines (85 loc) · 2.34 KB
/
blind.tool
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
94
95
#!/bin/bash
# brightness control for screens and keyboards (integrates with [thonkbar](https://github.com/JoseFilipeFerreira/thonkbar) and [range2color](toolbox/range2color))
bar_signal_id=36
emoji_array=("0" "1" "2" "3" "4" "5" "6")
name="$(basename "$0")"
usage(){
echo "NAME"
echo " $name - brightness manager"
echo
echo "SYNOPSIS"
echo " $name OPTIONS"
echo
echo "OPTIONS"
awk '/^ case/,/^ esac/' "$0" |
grep -E "^\s*(#|;;|[^*]\)|(-)*[a-zA-Z]*\))" |
sed -E 's/\|/, /g;s/(\)$)//g;s/# //g;s/;;//g'
}
[[ ! "$1" ]] && usage && exit
max="$(brightnessctl "${brightnessctl_args[@]}" max)"
n_step="${#emoji_array[@]}"
step="$(( max / (n_step - 1) ))"
[[ "$step" = 0 ]] && step=1
brightnessctl_args=( "--class=backlight" "--min-value=6" )
while (( "$#" )); do
case "$1" in
keyboard)
# Control the keyboard backlight
brightnessctl_args=( "--device=*kbd*" )
shift
;;
backlight)
# Control the screen backlight [default]
shift
;;
+)
# Increase brightness
set_value="+$step"
shift
;;
-)
# Decrease brightness
set_value="${step}-"
shift
;;
UP)
# Increase brightness, with id as next arg
set_value="+$step"
[[ "$2" ]] || exit
bar_signal_id="$2"
shift 2
;;
DOWN)
# Decrease brightness, with id as next arg
set_value="$step-"
[[ "$2" ]] || exit
bar_signal_id="$2"
shift 2
;;
--block)
# Print a block compatible with Thonkbar
print_block="true"
shift
;;
--help)
# Send this help message and exit
usage
exit
;;
*)
shift
esac
done
if [[ "$set_value" ]]; then
brightnessctl "${brightnessctl_args[@]}" set "${set_value}"
pkill --signal "$bar_signal_id" thonkbar
fi
if [[ "$print_block" ]]; then
curr="$(brightnessctl "${brightnessctl_args[@]}" get)"
echo "${emoji_array[curr/ step]}"
range2color \
--max-color "#FFFFFF" \
--min-color "#727169" \
--max "$max" \
"$curr"
fi