-
Notifications
You must be signed in to change notification settings - Fork 0
/
backlightctl
executable file
·55 lines (48 loc) · 1.48 KB
/
backlightctl
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
#!/usr/bin/env bash
# Notify backlight status (0: no, 1: yes) can be overwrite by providing this value as a second argument
arg2=$2
notify=${arg2:-0}
# Get backlight name
name=$(ls /sys/class/backlight/ | awk '{print $1}')
# Get actual brightness
current=$(cat /sys/class/backlight/$name/actual_brightness)
# Get max brightness
max=$(cat /sys/class/backlight/$name/max_brightness)
# Store arg
arg=$1
plus() {
arg=$(echo $arg | sed "s/+//g")
value=$(( current + arg ))
[ $value -gt $max ] && value=$max
[ $value -lt 1 ] && value=1
echo $value > /sys/class/backlight/$name/brightness
msg="$value/$max"
[ $notify -eq 1 ] && notify-send --urgency=low "💡 Backlight changed" "$msg" && exit
echo $msg
exit
}
minus() {
arg=$(echo $arg | sed "s/-//g")
value=$(( current - arg ))
[ $value -gt $max ] && value=$max
[ $value -lt 1 ] && value=1
echo $value > /sys/class/backlight/$name/brightness
msg="$value/$max"
[ $notify -eq 1 ] && notify-send --urgency=low "💡 Backlight changed" "$msg" && exit
echo $msg
exit
}
value() {
value=$arg
[ $value -gt $max ] && value=$max
[ $value -lt 1 ] && value=1
echo $value > /sys/class/backlight/$name/brightness
msg="$value/$max"
[ $notify -eq 1 ] && notify-send --urgency=low "💡 Backlight changed" "$msg" && exit
echo $msg
exit
}
[ -z "$(echo $arg | grep "+")" ] || plus
[ -z "$(echo $arg | grep "-")" ] || minus
[ -z "$(echo $arg | grep "[0-9]")" ] || value
exit -1