-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbright
More file actions
executable file
·47 lines (37 loc) · 1.42 KB
/
Copy pathbright
File metadata and controls
executable file
·47 lines (37 loc) · 1.42 KB
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
#!/usr/bin/env bash
TYPE=$1
MAX_BRIGHT=$(cat /sys/class/backlight/intel_backlight/max_brightness | xargs echo)
MIN_BRIGHT=$(echo "$MAX_BRIGHT * 0.08" | bc)
BRIGHT=$(cat /sys/class/backlight/intel_backlight/brightness | xargs echo)
STEP=$(echo "$MAX_BRIGHT * 0.05" | bc)
if [ ! -w "/sys/class/backlight/intel_backlight/brightness" ]
then
echo "'/sys/class/backlight/intel_backlight/brightness' is not writable!"
echo "Please execute 'sudo chmod o+w /sys/class/backlight/intel_backlight/brightness'"
echo "so that you can use this script without super user privileges."
exit 1
fi
if [ "$TYPE" = "down" ]
then
NEW_BRIGHT=$(echo "scale=0; ($BRIGHT - $STEP) / 1" | bc)
elif [ "$TYPE" = "up" ]
then
NEW_BRIGHT=$(echo "scale=0; ($BRIGHT + $STEP) / 1" | bc)
else
echo "Usage syntax: bright (up|down)"
exit 1
fi
if (( $(echo "$NEW_BRIGHT <= $MIN_BRIGHT" | bc -l) )) && [ "$TYPE" != "up" ]
then
echo "Impossible to decrease bright. It is already in the min level."
exit 1
fi
if (( $(echo "$NEW_BRIGHT >= $MAX_BRIGHT" | bc -l) )) && [ "$TYPE" != "down" ]
then
echo "Impossible to increase bright. It is already in the max level."
exit 1
fi
PERC_BRIGHT_ORIG=$(echo $(( 100 * $BRIGHT / $MAX_BRIGHT )) )
PERC_BRIGHT=$(echo $(( 100 * $NEW_BRIGHT / $MAX_BRIGHT )) )
echo "$NEW_BRIGHT" | tee /sys/class/backlight/intel_backlight/brightness
echo "Bright changed from $PERC_BRIGHT_ORIG% to $PERC_BRIGHT%."