diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-06 21:45:47 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-06 21:47:11 -0500 |
commit | 1082e1228dcc6912d705c03beab1a2d6a1c9f0b9 (patch) | |
tree | 487312dfd6f8b857b58b0c3084498b38cbfb678d | |
parent | 79591fa2783cc6e4c0b0478bcd711a6fbceec7a9 (diff) |
bin/backlight: flesh out
-rwxr-xr-x | .local/bin/backlight | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/.local/bin/backlight b/.local/bin/backlight index 0657030..cf48dca 100755 --- a/.local/bin/backlight +++ b/.local/bin/backlight @@ -1,6 +1,20 @@ #!/bin/bash -backlight=intel_backlight -pct=$1 -read max < /sys/class/backlight/$backlight/max_brightness -bc <<<"scale=2; $max * ($pct/100)" | cut -d. -f1 > /sys/class/backlight/$backlight/brightness +[[ -n "$BACKLIGHT" ]] || BACKLIGHT=intel_backlight +fmax=/sys/class/backlight/$BACKLIGHT/max_brightness +fcur=/sys/class/backlight/$BACKLIGHT/brightness +read max < $fmax || exit $? +case $# in + 0) + read cur < $fcur + bc <<<"100*$cur/$max" | cut -d. -f1 + ;; + 1) + declare -i pct="$1" + bc <<<"$max*$pct/100" | cut -d. -f1 > $fcur + ;; + *) + echo "Usage: [BACKLIGHT=<device_id>] backlight [<percent>]" >&2 + exit 1 + ;; +esac |