Battery status in tmux status bar in FreeBSD
On my FreeBSD laptop I switched back from the i3 window manager to the ratpoison window manager. I have been running ratpoison for more than a decade and only switched to i3 about two years ago. So, now I am back at ratpoison.
In ratpoison, I have no dock or permanent visible status bar.
I start tmux from
.xinitrc so it is always running in my first ratpoison window
(window number zero). Most of the time I am in this window.
So, the tmux status bar is a useful location for displaying the battery status.
Just enough information
I don't need much information to be shown in the status bar.
When the charger is connected, I want to know how far the charging is.
When on battery, I want to know what the remaining battery time is.
For this, I created a small script ```~/bin/battery.sh````:
#!/bin/sh STATE=`sysctl -n hw.acpi.battery.state` if [ $STATE -eq 2 ]; then echo "chg" $(sysctl hw.acpi.battery.life | cut -d : -f 2) "%" else echo "batt:" $(apm | grep time | head -n 1 | cut -d : -f 2,3) "h" fi
This results in the following format:
- When the charger is connected:
chg 86 %
- When on battery:
batt: 3:44 h
For me, this is just enough.
.tmux.conf there is the following line:
set -g status-right "#(~/bin/battery.sh) | %A %d-%b-%y %H:%M"
This displays the battery status, the day of the week, the date and
the time (in 24 hours format) at the right side of the status bar,
chg 88 % | Saturday 04-Dec-21 21:40.