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