summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2016-12-13 22:13:05 +0100
committerclsr <clsr@clsr.net>2016-12-13 22:13:05 +0100
commit8a4d5192eae47b13aee9d0fa52365e726e1479d4 (patch)
tree25d65f2edd0300e3ad5d1036e3a02bb51d896b37
downloadbl-master.tar.gz
bl-master.zip
Initial commitHEADv1.0.0master
-rwxr-xr-xbl55
1 files changed, 55 insertions, 0 deletions
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"