diff options
author | clsr <clsr@clsr.net> | 2016-12-13 22:13:05 +0100 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2016-12-13 22:13:05 +0100 |
commit | 8a4d5192eae47b13aee9d0fa52365e726e1479d4 (patch) | |
tree | 25d65f2edd0300e3ad5d1036e3a02bb51d896b37 | |
download | bl-8a4d5192eae47b13aee9d0fa52365e726e1479d4.tar.gz bl-8a4d5192eae47b13aee9d0fa52365e726e1479d4.zip |
-rwxr-xr-x | bl | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -0,0 +1,55 @@ +#!/bin/sh + +# This software is released into the public domain. +# It is provided "as is", without warranties or conditions of any kind. +# Anyone is free to use, modify, redistribute and do anything with this software. + +set -e + +if [ -n "$BACKLIGHT" ]; then + bldir="/sys/class/backlight/$BACKLIGHT" +else + for f in /sys/class/backlight/*; do + if [ -n "$bldir" ]; then + echo "too many backlights found, choose one with \$BACKLIGHT" >&2 + exit 1 + fi + bldir="$f" + done +fi +if [ -z "$bldir" ] || ! [ -d "$bldir" ]; then + echo "no backlight found" >&1 + exit 1 +fi +curr=$(($(cat "$bldir/brightness")+0)) +max=$(($(cat "$bldir/max_brightness")+0)) +mod="$1" +case "$mod" in + +|-) + new="$((curr${mod}max/100))" + ;; + +[1-9]*|-[1-9]*) + new="$((curr$mod*max/100))" + ;; + [0-9]*) + new="$((mod*max/100+1))" + ;; + =[0-9]*) + new="${mod#=*}" + ;; + =) + echo "$curr" + exit + ;; + '') + echo "$((curr*100/max))" + exit + ;; + *) + echo "usage: $(basename "$0") [ +-=][0-100]" >&2 + exit 2 + ;; +esac +[ "$new" -gt "$max" ] && new="$max" +[ "$new" -lt 1 ] && new=1 +echo "$new" > "$bldir/brightness" |