summaryrefslogtreecommitdiff
path: root/.local/bin/backlight
blob: cf48dcaee2e3cea18300eef3f35f2a21e44af80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

[[ -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