ref: a3188c16c2d36b1e3262955452bff6c36edc3f48 dotfiles/overlay/bin/dpmsconf -rwxr-xr-x 1.4 KiB View raw
                                                                                
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
#!/bin/sh

set -e
set -u

config_file="$(apply-dpms printcfg)"

ac_choices="5!10!15!30!60!never"
bat_choices="$ac_choices"

# set default to current values, if any
if [ -e "$config_file" ] ; then
	ac_current="$(cat "$config_file" | awk '$1 ~ /AC/ {print($2)}')"
	bat_current="$(cat "$config_file" | awk '$1 ~ /BAT/ {print($2)}')"

	if [ -z "$ac_current" ] ; then
		echo "" # no current AC config
	elif echo "$ac_choices" | grep "$ac_current" > /dev/null 2>&1 ; then
		ac_choices="$(echo "$ac_choices" | sed 's/'"$ac_current"'/^'"$ac_current"'/g')"
	else
		ac_choices="$(echo "$ac_choices!^$ac_current")"
	fi

	if [ -z "$bat_current" ] ; then
		echo "" # no current BAT config
	elif echo "$bat_choices" | grep "$bat_current" > /dev/null 2>&1 ; then
		bat_choices="$(echo "$bat_choices" | sed 's/'"$bat_current"'/^'"$bat_current"'/g')"
	else
		bat_choices="$(echo "$bat_choices!^$bat_current")"
	fi
else
	ac_choices="$(echo "$ac_choices" | sed 's/60/^60/g')"
	bat_choices="$(echo "$bat_choices" | sed 's/10/^10/g')"
fi

choice="$(yad --form --title "DPMS Profile" \
	--text "Configure DPMS profile" \
	--field="On AC":CB \
		"$ac_choices" \
	--field="On Battery":CB \
		"$bat_choices")"

ac_profile="$(echo "$choice" | awk -F '|' '{print $1}')"
bat_profile="$(echo "$choice" | awk -F '|' '{print $2}')"


printf "AC\t$ac_profile\n" > "$config_file"
printf "BAT\t$bat_profile\n" >> "$config_file"

apply-dpms