cfg/bin/tmux-battery
Knut Ahlers 782c6f2c4e
Update battery display with better symbols
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-11-17 21:00:58 +01:00

27 lines
445 B
Bash
Executable file

#!/bin/bash
set -euo pipefail
SYM_ADAPTER="$(printf '\ufba3')"
SYM_BATTERY="$(printf '\uf58d')"
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}%"