Skip to content
Simple way to get battery information (linux only)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

battery-d Page on DUB License CircleCI

battery-d - simple library for reading battery info on linux laptops. Provides access to battery status (discharging, charging or full), battery level (0-100%), time remaining and time until full. Also provides access to raw data (which can differ on different laptops).

Basic usage

dub run battery-d

As library

battery-d can be used as library. Just add it to dependencies in dub.json. Example usage:

import std.stdio;
import battery.d;

void main() {
	auto b = new Battery();
	writeln("Level: ", b.level);
	writeln("Status: ", b.status);


Advanced usage

battery-d have been developed as rewrite of old perl script, which parses output of acpi command. By default battery-d -pc outputs coloured battery level:

  • <= 20% - red
  • <= 50% - yellow
  • <= 100% - green

Output can be customized by editing code or cli arguments:

battery-d -pc --threshold=30=["%F{orange}","%%%f"]

This command adds new threshold, which prepends battery level with %F{orange} and appends %%%f. Output will look like this:

In zsh it produces orange-coloured `29%`.
You can’t perform that action at this time.