Update ERC setup
[~bandali/configs] / .local / bin / battery-percentage-time
... / ...
CommitLineData
1#!/bin/sh
2dbus_send() {
3 label=$1
4 dbus-send --print-reply=literal --system \
5 --dest=org.freedesktop.UPower \
6 /org/freedesktop/UPower/devices/battery_BAT0 \
7 org.freedesktop.DBus.Properties.Get \
8 string:org.freedesktop.UPower.Device \
9 string:"${label}" | awk '{print $3}'
10}
11
12perc=$(dbus_send 'Percentage')
13state=$(dbus_send 'State')
14
15if [ "$state" -eq 2 ]; then # Discharging
16 secs=$(dbus_send 'TimeToEmpty')
17elif [ "$state" -eq 1 ]; then # Charging
18 secs=$(dbus_send 'TimeToFull')
19fi
20
21printf '%s%%%%%2dh%02dm \n' "$perc" $((secs / 3600)) $((secs % 3600 / 60))