• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Shell
  • License
    ISC License
  • Created almost 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”‹ CLI battery status indicator for macOS, Linux, and OpenBSD ⚑

battstat

battstat is a shell script that displays formatted information about the status of your battery.

Information is displayed in the order the format tokens are written. For example, the screenshots below show my tmux status line running the command battstat --percent-when-charged {i} {t} {p}. This will display an icon, the time remaining when charging and discharging, and finally the percentage but only when the battery is fully charged. Format tokens can be written in any order and as many times as you like.

battery charging battery discharging battery full charged

Examples

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 "πŸ•" {t} {i}
 10:30  πŸ•

$ battstat {t} {i}
 11:47  πŸ”‹

$ battstat -c "AC:" -d "BAT:" {i} {p} {t}
 BAT:  82%  12:11

$ battstat {i} {p}    
 πŸ”‹  81%

$ battstat -d "Battery:" {i} {p}
 Battery:  81%

macOS menu bar

bitbar screenshot

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 {t})

echo "($time) | size=13"

Supported Operating Systems

  • macOS: Details are collected via pmset(1).
  • Linux: Details are collected via upower(1).
  • OpenBSD: Details are collected via apm(8).

Notes

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.

Install

  1. 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
  2. Move it to your favorite binary path and make it executable.

$ mv battstat /usr/local/bin
$ chmod u+x /usr/local/bin/battstat

Usage

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
    --percent-when-charged    only display percent when charged

format:
    {i}    display icon
    {t}    display time remaining
    {p}    display percent

    Note: There must be a space between each format token.

More Repositories

1

coffeeconnect

Connect to Starbucks WiFi without opening a browser.
Shell
41
star
2

scripts

Various shell scripts to make my life easier.
Shell
32
star
3

love-a-paper

Twitter bot that tweets randomly selected papers from Papers We Love.
Go
20
star
4

untweet

Destroy tweets and likes.
Go
15
star
5

pin

Simple command line pinboard client.
Go
13
star
6

pinboard

Pinboard golang package.
Go
12
star
7

cmuck

mucking about with c
C
7
star
8

cable2text

Convert wikileaks cables from HTML to plain text.
Python
4
star
9

aoc2018

Advent of Code 2018 Solutions
Go
3
star
10

emacsd

emacs configuration files.
Emacs Lisp
3
star
11

dotfiles

various unix config files
Shell
3
star
12

linkview

Terminal HTML link menu.
Go
2
star
13

feather-temp

Read the temperature using a feather board + TMP36 sensor.
C++
2
star
14

imwally.github.com

A redirect to my homepage, for now.
HTML
2
star
15

gol-py

Conway's Game of Life in Python
Python
1
star
16

gnome3

gnome3 configs
Shell
1
star
17

neopixel-hi

Hello, NeoPIxel
C++
1
star
18

rfcsearch

JSON API for RFC searches.
Go
1
star
19

niltheme

Pelican theme for nil.
HTML
1
star
20

rfcapropos

Like apropos(1) but for RFCs.
Go
1
star
21

aoc2021

Advent of Code 2021
Python
1
star
22

tlsfp-py

TLS Fingerprints but now in python!
Python
1
star
23

nil

nil null nada nothing
Makefile
1
star
24

hashma

Hash Match
Go
1
star
25

imwally

1
star
26

hello-world

We all start at the bottom.
1
star
27

certify

Go
1
star
28

freebird

For I must be traveling on, now cause there's too many places I've got to see
Go
1
star
29

knr

C
1
star
30

blaster

A RESTful API for you music collection.
Go
1
star
31

tlsplain

Explain a TLS connection.
Go
1
star
32

httpracer

Time HTTP connections.
Go
1
star