Skip to content

fix(tmux): parse macOS battery status#111

Draft
ALX99 wants to merge 1 commit into
masterfrom
audit/fix-tmux-macos-battery-status
Draft

fix(tmux): parse macOS battery status#111
ALX99 wants to merge 1 commit into
masterfrom
audit/fix-tmux-macos-battery-status

Conversation

@ALX99

@ALX99 ALX99 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Problem and impact

On macOS, the tmux status script rendered an empty battery percentage because its extended-regex parser used \d, which POSIX grep -E does not define as a digit class. It also matched charging inside discharging, so a low discharging battery could use the charging colour instead of the warning/critical colour.

Reproduction and observed result

Validated against untouched master commit 52ea8ecd508b4cb3cc529a3c6d3f69696cbf2060 with the exact current script in a fresh temporary Git repository. Temporary uname and pmset stubs selected the real Darwin branch and emitted standard battery rows.

With 12%; discharging, the parent printed:

#[fg=colour245]bat #[fg=colour75]%#[fg=default]

With 87%; charging, it also printed an empty percentage. Directly running the parent expression with GNU grep 3.11 produced no match for 87%.

Root cause and fix

The Darwin parser used grep -Eo "\d+%" and an unbounded case-insensitive search for charging.

The fix uses the portable ERE [0-9]+% and matches charging only as a complete semicolon/whitespace-delimited status word. Linux battery handling and status-line assembly are unchanged.

Validation commands and results

  • bash -n .config/tmux/status — passed.
  • Exact before/after harness with GNU Bash 5.2.37 and GNU grep 3.11:
    • 12%; discharging12% with the critical colour.
    • 87%; charging87% with the charging colour.
    • 100%; charged100% without being misclassified as charging.
  • git diff --check — passed.
  • Branch comparison to current master — one commit, zero commits behind, one modified file, two additions and two deletions.
  • GitHub Linter workflow (ShellCheck across all shebang files) — passed.
  • Local ShellCheck installation was also attempted through the approved internal Debian mirror, but the mirror returned HTTP 503; CI supplied the authoritative ShellCheck result.

Scope and risk

Only .config/tmux/status changes. No tests, configuration contracts, Linux behavior, generated files, dependencies, or unrelated code are modified. The risk is limited to parsing pmset -g batt text on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant