-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVbrightness
executable file
·46 lines (40 loc) · 1.33 KB
/
Vbrightness
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
#!/bin/zsh
. Vlib.sh
. Vglobals
if [ "$#" -ne 1 ]; then
echo "no argument";
exit 1;
fi
# Constants
path_to_brightness="/sys/class/backlight/intel_backlight";
path_to_toggle="$(REQUIRE_CACHE vbrightness 0)";
new_brightness=111;
min_brightness=1;
current_brightness=$(cat $path_to_brightness/brightness);
max_brightness=$(cat $path_to_brightness/max_brightness);
if [ $1 = "+" ]; then
new_brightness=$((current_brightness + BRIGHTNESS_DERIVATIVE_SLOPE));
if ((new_brightness > max_brightness)); then new_brightness=$((max_brightness - 10)); fi
elif [ $1 = "-" ]; then
new_brightness=$((current_brightness - BRIGHTNESS_DERIVATIVE_SLOPE));
if ((new_brightness < min_brightness)); then new_brightness=$min_brightness; fi
elif [ $1 = "0" ]; then
if [[ $current_brightness -ne $min_brightness ]]; then
echo $current_brightness > $path_to_toggle;
new_brightness=$min_brightness;
else
new_brightness=$(cat $path_to_toggle);
# wrong brightness written to file
if ((new_brightness < min_brightness || new_brightness > max_brightness)); then
echo "wrong brightness in $path_to_toggle file";
new_brightness=$((min_brightness + 77));
fi
fi
elif [ $1 = "%" ]; then
echo $((current_brightness * 100 / max_brightness + 1));
exit 0;
else
echo "argument must be +, -, % or 0";
exit 2;
fi
echo $new_brightness > $path_to_brightness/brightness;