Enjoying Open Source Software

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 my .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/````:


STATE=`sysctl -n hw.acpi.battery.state`

if [ $STATE -eq 2 ]; then
   echo "chg" $(sysctl | cut -d : -f 2) "%"
   echo "batt:" $(apm | grep time | head -n 1 | cut -d : -f 2,3) "h"


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.


In .tmux.conf there is the following line:

set -g status-right "#(~/bin/ | %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, like chg 88 % | Saturday 04-Dec-21 21:40.


See also this page.


⇽ mcabber with OTR on FreeBSD Why RSS is important ⇾