2018-04-19 09:06:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2018-11-16 23:27:16 +00:00
|
|
|
SYM_ADAPTER="$(printf '\ufba3')"
|
|
|
|
SYM_BATTERY="$(printf '\uf58d')"
|
2018-04-19 09:06:31 +00:00
|
|
|
BATTERY=/sys/class/power_supply/BAT0
|
|
|
|
AC=/sys/class/power_supply/AC
|
|
|
|
|
2018-11-16 23:27:16 +00:00
|
|
|
[ -e ${BATTERY} ] || {
|
|
|
|
echo "No battery" >&2
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
[ -e ${AC} ] || {
|
|
|
|
echo "No ac" >&2
|
|
|
|
exit 0
|
|
|
|
}
|
2018-04-19 09:06:31 +00:00
|
|
|
|
|
|
|
CAPACITY=$(cat ${BATTERY}/capacity)
|
|
|
|
AC_CONNECT=$(cat ${AC}/online)
|
|
|
|
|
|
|
|
if [ ${AC_CONNECT} -eq 0 ]; then
|
2018-11-16 23:27:16 +00:00
|
|
|
SYM=${SYM_BATTERY}
|
2018-04-19 09:06:31 +00:00
|
|
|
else
|
2018-11-16 23:27:16 +00:00
|
|
|
SYM=${SYM_ADAPTER}
|
2018-04-19 09:06:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${SYM} ${CAPACITY}%"
|