summaryrefslogtreecommitdiff
path: root/scripts/slight
blob: 50f4a5468953a72141cdd9ff8ab411d56497e934 (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
56
57
58
59
60
61
62
#!/bin/sh

help() {
cat << EOF
$0: Wrapper script to change backlight

options:
 -i [Brg]	Increase backlight by Brg
 -d [Brg]	Decrease backlight by Brg
 -s [Brg] 	Set backlight to Brg
 -p		Show the current backlight
 -h 		Print this message and exit

NOTE: Script interprets values as percentages
EOF
}

err() {
	printf "$*\n"
	exit 1
}

run() {
	if ! $(${1} > /dev/null 2>&1); then
		err "%s""${2}"
	fi
}


if [ $# != 1 ] && [ $# != 2 ]; then
	err "${0}: Invalid usage\nTry '$0 -h' for help."
fi

if ! command -v brightnessctl > /dev/null 2>&1; then
	err "brightnessctl must be installed"
fi

while getopts "i:d:s:ph" option; do
	case "${option}" in
	i)
		run "brightnessctl set +${OPTARG}%" \
		"${0}: Failed to increase brightness"
	;;
	d)
		run "brightnessctl set ${OPTARG}-%" \
		"${0}: Failed to decrease brightness"
	;;
	s)
		run "brightnessctl set ${OPTARG}%" \
		"${0}: Failed to set brightness"
	;;
	p)
		if ! brightnessctl 2>/dev/null; then
			err "Failed to get current brightness"
		fi
	;;
	h) help; exit 0 ;;

	*) err "Try '$0 -h' for help.";;

	esac
done