From 8a4d5192eae47b13aee9d0fa52365e726e1479d4 Mon Sep 17 00:00:00 2001 From: clsr Date: Tue, 13 Dec 2016 22:13:05 +0100 Subject: Initial commit --- bl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 bl diff --git a/bl b/bl new file mode 100755 index 0000000..d75ad3d --- /dev/null +++ b/bl @@ -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" -- cgit