29 lines
706 B
Bash
29 lines
706 B
Bash
#!/usr/bin/env bash
|
|
|
|
BAT_PATH='/sys/class/power_supply/BAT0'
|
|
|
|
if [ ! -d "${BAT_PATH}" ]; then
|
|
printf '{"text": "\u221e%% \ue55b", "tooltip": "UNLIMITED POWER", "class": "desktop"}\n'
|
|
exit 0
|
|
fi
|
|
|
|
capacity="$(cat "${BAT_PATH}/capacity")"
|
|
status="$(cat "${BAT_PATH}/status")"
|
|
|
|
if [ "${status}" = "Charging" ]; then
|
|
icon='\ue55b'
|
|
elif [ "${capacity}" -ge 90 ]; then
|
|
icon='\uf240'
|
|
elif [ "${capacity}" -ge 75 ]; then
|
|
icon='\uf241'
|
|
elif [ "${capacity}" -ge 50 ]; then
|
|
icon='\uf242'
|
|
elif [ "${capacity}" -ge 25 ]; then
|
|
icon='\uf243'
|
|
else
|
|
icon='\uf244'
|
|
fi
|
|
|
|
printf '{"text": "%s%% %s", "tooltip": "Status: %s", "class": "%s"}\n' \
|
|
"${capacity}" "${icon}" "${status}" "${status}"
|
|
|