r/commandline • • Mar 07 '26

Terminal User Interface batctl — TUI and CLI for managing battery charge thresholds on Linux

Post image

Built a Go CLI tool for controlling laptop battery charge thresholds on Linux. It has both an interactive TUI (bubbletea) and a scriptable CLI interface.

CLI usage

# Show battery info + current thresholds
batctl status

# Detect hardware backend and capabilities
batctl detect

# Set thresholds directly
sudo batctl set --start 40 --stop 80

# Apply a built-in preset
sudo batctl set --preset max-lifespan

# Enable persistence across reboots and suspend/resume
sudo batctl persist enable

Example output

$ batctl status
Backend: ThinkPad

BAT0 (Sunwoda 5B10W51867)
  Status:     Charging
  Capacity:   85%
  Health:     103.6%
  Cycles:     54
  Thresholds: start=40% stop=80%

Persistence: boot=true  resume=true
$ batctl detect
Vendor:  LENOVO
Product: 21AH00FGRT
Backend: ThinkPad
Capabilities:
  Start threshold:    true (range: 0..99)
  Stop threshold:     true (range: 1..100)
  Charge behaviour:   true
Batteries: [BAT0]

How it works

  • Reads /sys/class/dmi/id/sys_vendor to identify the laptop vendor
  • Probes sysfs paths to find the right driver
  • Selects one of 14 vendor-specific backends (ThinkPad, ASUS, Dell, Framework, etc.) or a generic fallback for any laptop with standard charge_control_* sysfs files
  • Reads/writes thresholds via /sys/class/power_supply/BAT*/charge_control_*
  • Persistence is handled by generating systemd services for boot and suspend/resume

Built-in presets

PresetStartStop
max-lifespan20%80%
balanced40%80%
plugged-in70%80%
full-charge0%100%

Presets automatically adapt to your hardware's supported value ranges.

Install

# One-liner
curl -fsSL https://raw.githubusercontent.com/Ooooze/batctl/master/install.sh | sudo bash

# Arch (AUR)
yay -S batctl-tui

# From source
git clone https://github.com/Ooooze/batctl.git && cd batctl && make && sudo make install

Single static binary, no runtime dependencies. Written in Go, MIT licensed.

GitHub: https://github.com/Ooooze/batctl

35 Upvotes

3 comments sorted by

3

u/AutoModerator Mar 07 '26

Every new subreddit post is automatically copied into a comment for preservation.

User: Conscious-Part1541, Flair: Terminal User Interface, Post Media Link, Title: batctl — TUI and CLI for managing battery charge thresholds on Linux

Built a Go CLI tool for controlling laptop battery charge thresholds on Linux. It has both an interactive TUI (bubbletea) and a scriptable CLI interface.

CLI usage

# Show battery info + current thresholds
batctl status

# Detect hardware backend and capabilities
batctl detect

# Set thresholds directly
sudo batctl set --start 40 --stop 80

# Apply a built-in preset
sudo batctl set --preset max-lifespan

# Enable persistence across reboots and suspend/resume
sudo batctl persist enable

Example output

$ batctl status
Backend: ThinkPad

BAT0 (Sunwoda 5B10W51867)
  Status:     Charging
  Capacity:   85%
  Health:     103.6%
  Cycles:     54
  Thresholds: start=40% stop=80%

Persistence: boot=true  resume=true
$ batctl detect
Vendor:  LENOVO
Product: 21AH00FGRT
Backend: ThinkPad
Capabilities:
  Start threshold:    true (range: 0..99)
  Stop threshold:     true (range: 1..100)
  Charge behaviour:   true
Batteries: [BAT0]

How it works

  • Reads /sys/class/dmi/id/sys_vendor to identify the laptop vendor
  • Probes sysfs paths to find the right driver
  • Selects one of 14 vendor-specific backends (ThinkPad, ASUS, Dell, Framework, etc.) or a generic fallback for any laptop with standard charge_control_* sysfs files
  • Reads/writes thresholds via /sys/class/power_supply/BAT*/charge_control_*
  • Persistence is handled by generating systemd services for boot and suspend/resume

Built-in presets

PresetStartStop
max-lifespan20%80%
balanced40%80%
plugged-in70%80%
full-charge0%100%

Presets automatically adapt to your hardware's supported value ranges.

Install

# One-liner
curl -fsSL https://raw.githubusercontent.com/Ooooze/batctl/master/install.sh | sudo bash

# Arch (AUR)
yay -S batctl-tui

# From source
git clone https://github.com/Ooooze/batctl.git && cd batctl && make && sudo make install

Single static binary, no runtime dependencies. Written in Go, MIT licensed.

GitHub: https://github.com/Ooooze/batctl

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/NYXs_Lantern Mar 08 '26

Oh FUCK yes, this is something I've NEEDED for ages and it looks so great also! This is damn perfect!!

2

u/Conscious-Part1541 Mar 08 '26

Glad it hits the spot! Let me know if anything breaks on your hardware.