cfg/bin/tmux-battery

28 lines
502 B
Text
Raw Permalink Normal View History

#!/bin/bash
set -euo pipefail
SYM_ADAPTER="$(printf '\U000f06a5')" # nf-md-power_plug
SYM_BATTERY="$(printf '\U000f008e')" # nf-md-battery_outline
BATTERY=/sys/class/power_supply/BAT0
AC=/sys/class/power_supply/AC
[ -e ${BATTERY} ] || {
echo "No battery" >&2
exit 0
}
[ -e ${AC} ] || {
echo "No ac" >&2
exit 0
}
CAPACITY=$(cat ${BATTERY}/capacity)
AC_CONNECT=$(cat ${AC}/online)
if [ ${AC_CONNECT} -eq 0 ]; then
SYM=${SYM_BATTERY}
else
SYM=${SYM_ADAPTER}
fi
echo "${SYM} ${CAPACITY}%"