-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbacklight_intel_notebook
executable file
·68 lines (59 loc) · 2.12 KB
/
backlight_intel_notebook
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
#!/bin/bash -e
usage() {
cat << EOF
Usage: backlight_intel_notebook
Set the brightness using the "intel_backlight" kernel module interface. Useful
when "xbacklight" does not work. Options are equivalent to the same as
xbacklight offers but following double-dashed format for long options.
If no option is given the argument is passed on as a raw brightness selection
value.
Options:
-v, --verbose execute with verbose output
-h, -?, --help display this help
-n, --dry-run execute in dry-run mode
-g, --get get brightness in percentage
-s <percentage>, --set <percentage> set brightness in percentage
-i <percentage>, --inc <percentage> increase brightness by percentage
-d <percentage>, --dec <percentage> decrease brightness by percentage
Examples:
backlight_intel_notebook 120000
backlight_intel_notebook --get
backlight_intel_notebook --set 100
EOF
exit
}
set -o pipefail
opts=$(getopt -o vhns:i:d:g --long verbose,help,dry-run,set:,inc:,dec:,get -n 'parse-options' -- "$@") || usage
eval set -- "$opts"
while true; do
case "$1" in
-v | --verbose ) set -x; shift ;;
-h | --help ) usage; shift ;;
-n | --dry-run ) dry_run=true; shift ;;
-g | --get ) get=true; shift 2 ;;
-s | --set ) set="$2"; shift 2 ;;
-i | --inc ) inc="$2"; shift 2 ;;
-d | --dec ) dec="$2"; shift 2 ;;
-- ) shift; break ;;
* ) break ;;
esac
done
brightness=$(cat /sys/class/backlight/intel_backlight/brightness)
if [ -n "$get" ]; then
echo "$brightness"
exit 0
fi
max_brightness=$(cat /sys/class/backlight/intel_backlight/max_brightness)
if [ -n "$set" ]; then
new_brightness=$((max_brightness * set / 100))
elif [ -n "$inc" ]; then
new_brightness=$((brightness + max_brightness * inc / 100))
elif [ -n "$dec" ]; then
new_brightness=$((brightness - max_brightness * dec / 100))
fi
new_brightness="${new_brightness:-${1:-"90"}}"
if [ -n "$dry_run" ]; then
echo "$0: dry run: Would set $new_brightness"
else
echo $new_brightness | sudo tee /sys/class/backlight/intel_backlight/brightness >/dev/null
fi