Battery status in tmux status bar in FreeBSD
Ratpoison
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.
tmux
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.
Script
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
Format
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
In .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,
like chg 88 % | Saturday 04-Dec-21 21:40
.
Resources
Made with ♥ by a human - Proud member of the 250kb.club.
Most recent pages
All tags
Sitemap
RSS
RSS of Gophersite