X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;ds=sidebyside;f=bin%2Fbacklight_adjust;fp=bin%2Fbacklight_adjust;h=5c74ff9cc36bdd79d612286b0d24ae8126d3b565;hb=70ece610f56912fee47262606f75f4c139c71aff;hp=0000000000000000000000000000000000000000;hpb=d02666562301630555916c5badbccbd5e60cdcab;p=khome.git diff --git a/bin/backlight_adjust b/bin/backlight_adjust new file mode 100755 index 0000000..5c74ff9 --- /dev/null +++ b/bin/backlight_adjust @@ -0,0 +1,31 @@ +#! /bin/sh + +set -e + +fun="$1" +screen_brightness_device_path="/sys/class/backlight/intel_backlight" + +# Padding with space because when fun="=10", awk fails to parse fun==10 +new=$( + awk -v fun=" $fun" ' + FILENAME ~ "/max_brightness$" {max = $1; next} + FILENAME ~ "/brightness$" {cur = $1; next} + + END { + unit = max / 100 + oper = substr(fun, 2, 1) + units = substr(fun, 3, length(fun) - 1) + if (oper == "=") {new = unit * units} else + if (oper == "+") {new = cur + (unit * units)} else + if (oper == "-") {new = cur - (unit * units)} else { + printf("Unrecognized operator: %s\n", oper) > "/dev/stderr" + exit(1) + } + print int(new) + } + ' \ + "$screen_brightness_device_path/max_brightness" \ + "$screen_brightness_device_path/brightness" +) + +echo "${new}" | tee "${screen_brightness_device_path}/brightness"