aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/bin/barbatwatt
blob: 3ac93dfa283c6dc69cd0c1e56ea650395b79fa6a (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
#!/bin/sh
# Show the charge or discharge rate of the battery

rate="$(printf "scale=3\n%s\n" "$(grep 'POWER_SUPPLY_POWER_NOW' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}') / 1000000" | bc)"
stat="$(grep 'POWER_SUPPLY_STATUS' /sys/class/power_supply/BAT0/uevent | awk -F '=' '{print $2}')"

if [ "$1" = "-p" ]; then
	# Output in plain text
	echo "Battery $stat at a rate of ${rate}W"
	exit 0
fi

if [ "$stat" = "Charging" ]; then
	tooltip="Battery is charging at a rate of"
	arrow="↑"
	color="#5b8277"
elif [ "$stat" = "Discharging" ]; then
	tooltip="Battery is discharging at a rate of"
	arrow="↓"
	color="#b2872f"
else
	tooltip="Battery is not charging"
	arrow=""
	color="#fcf8e2"
fi

printf '{ "class": "%s", "text": "<span color=\\"%s\\">%s</span> %sW", "tooltip": "%s: %sW" }' "$stat" "$color" "$arrow" "$rate" "$tooltip" "$rate"