summaryrefslogtreecommitdiffstats
path: root/bl
blob: d75ad3debe0ad53c4d76e91dccb313ca87b63155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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"