aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/bar/brightness
blob: 3ce40763941e1dc548d640f0caadaa9ee1adf66a (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
#!/bin/bash

# A script to manage screen brightness on my machine
# Depends on: bash, brightnessctl, libnotify
# By David Penkowoj, 2024-09-16

memfile="/tmp/$(whoami)-brightness.memtxt"
monitor_id="amdgpu_bl2"

bctl() {
	brightnessctl --device="$monitor_id" "$@"
}

notify_brightness() {
	current="$(brightness get)"
	max="$(bctl m)"
	notify-send -u low -r "110" "Screen brightness: $(( current * 100 / max ))%"
}

case "$1" in
	"up")
		bctl set +5%
		notify_brightness
		;;
	"down")
		bctl set 5-%
		notify_brightness
		;;
	"get")
		printf "%s\n" "$(bctl | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)"
		;;
	*)
		printf "[ Error ] Usage: brightness [up|down|get]"
		exit 1
		;;
esac