summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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"