#!/bin/bash # omarchy:summary=Returns true if a battery is present on the system. # Not every battery is called BAT*: Apple Silicon reports macsmc-battery and # some Framework and Chromebook firmware CMB0, so decide by type, not by name. power_supply_path="${OMARCHY_POWER_SUPPLY_PATH:-/sys/class/power_supply}" for bat in "$power_supply_path"/*; do [[ -r $bat/present && $(<"$bat/present") == "1" ]] || continue [[ -r $bat/type && $(<"$bat/type") == "Battery" ]] || continue # A wireless mouse or keyboard registers a Battery too, scoped Device. The # one that powers the machine is scoped System, or unscoped on older drivers. [[ -r $bat/scope && $(<"$bat/scope") == "Device" ]] && continue exit 0 done exit 1