battstat
is a shell script that displays formatted information about the status of your battery.
There are a few ways to customize the output of battstat
. Charging and discharging icons can be replaced with single character or multi-character strings. The -c
flag sets the charging string and the -d
flag sets the discharging string.
~ % battstat -d "π"
11:25 74% π
~ % battstat -d "π" -f "{i} ({t})"
π (11:15)
~ % battstat -c "AC:" -d "BAT:" -f "{i} {p} {t}"
BAT: 74% 11:35
~ % battstat -d "Battery:" -f "{i} {p}"
Battery: 74%
battstat
uses printf style formatting when using the -f
flag. This means you can print replacement tokens however you want.
~ % battstat -f "{i}\t{t}\t({p})"
π 11:55 (74%)
~ % battstat -f "{i}\nType whatever you want.\n{t}\n({p})"
π
Type whatever you want.
12:05
(73%)
Using bitbar you can add the output of battstat
to the menu bar on macOS. There are many ways to customize the output so I suggest reading over the writing plugins section to understand what's possible.
The screenshot above is using the following shell script. Make sure the script is executable and placed in the bitbar plugins path.
#!/bin/sh
time=$(/usr/local/bin/battstat -f {t})
echo "($time) | size=13"
- macOS: Details are collected via
pmset(1)
. - Linux: Details are collected via
upower(1)
. - OpenBSD: Details are collected via
apm(8)
.
The script does not account for laptops with multiple batteries. Newer ThinkPad models include both a swappable and non-swappable battery which may cause problems when searching for the battery with upower
. I currently don't have the means necessary to test against these models but pull requests are of course welcomed.
-
Grab the script. Here are a few options:
- Download and extract the zip.
$ git clone https://github.com/imwally/battstat
$ curl -O https://raw.githubusercontent.com/imwally/battstat/master/battstat
-
Move it to your favorite binary path and make it executable.
$ mv battstat /usr/local/bin
$ chmod u+x /usr/local/bin/battstat
usage: battstat [options] format
options:
-h, --help display help information
-c, --charging-icon string to display in icon's place when battery is charging
-d, --discharging-icon string to display in icon's place when battery is discharging
-f, --format formatted output of battstat
--percent-when-charged only display percent when charged
format replacement tokens:
{i} display icon
{t} display time remaining
{p} display percent
example:
battstat -f "Cool Battery: {t} ({p})"