master ohmu/dihfiles / bin / bat.sh
ohmu  ·  2026-09-26
 1#!/bin/sh
 2
 3battery_path="/sys/class/power_supply/BAT0"
 4[ -d "$battery_path" ] || battery_path="/sys/class/power_supply/BAT1"
 5[ -d "$battery_path" ] || exit 1
 6
 7capacity=$(cat "$battery_path/capacity" 2>/dev/null)
 8status=$(cat "$battery_path/status" 2>/dev/null)
 9
10[ -z "$capacity" ] && exit 1
11
12battery_info="${capacity}% (${status})"
13
14if command -v notify-send >/dev/null 2>&1; then
15    notify-send "battery" "$battery_info"
16elif command -v herbe >/dev/null 2>&1; then
17    herbe "battery: $battery_info"
18else
19    printf '%s\n' "$battery_info"
20fi