Commit | Line | Data |
---|---|---|
70ece610 SK |
1 | #! /bin/sh |
2 | ||
3 | set -e | |
4 | ||
5 | fun="$1" | |
6 | screen_brightness_device_path="/sys/class/backlight/intel_backlight" | |
7 | ||
8 | # Padding with space because when fun="=10", awk fails to parse fun==10 | |
9 | new=$( | |
10 | awk -v fun=" $fun" ' | |
11 | FILENAME ~ "/max_brightness$" {max = $1; next} | |
12 | FILENAME ~ "/brightness$" {cur = $1; next} | |
13 | ||
14 | END { | |
15 | unit = max / 100 | |
16 | oper = substr(fun, 2, 1) | |
17 | units = substr(fun, 3, length(fun) - 1) | |
18 | if (oper == "=") {new = unit * units} else | |
19 | if (oper == "+") {new = cur + (unit * units)} else | |
20 | if (oper == "-") {new = cur - (unit * units)} else { | |
21 | printf("Unrecognized operator: %s\n", oper) > "/dev/stderr" | |
22 | exit(1) | |
23 | } | |
24 | print int(new) | |
25 | } | |
26 | ' \ | |
27 | "$screen_brightness_device_path/max_brightness" \ | |
28 | "$screen_brightness_device_path/brightness" | |
29 | ) | |
30 | ||
31 | echo "${new}" | tee "${screen_brightness_device_path}/brightness" |