nixos-config/modules/workspace/i3blocks/scripts/battery.nix

49 lines
1.2 KiB
Nix
Raw Normal View History

2020-02-17 17:00:59 +04:00
{ acpi, bash, iconfont, low_threshold ? 10, ... }: ''
#!${bash}/bin/bash
BATTERY="`${acpi}/bin/acpi -b | grep --invert-match unavailable | head -1`"
STATUS=`awk -F'[,:] ' '{print $2}' <<< "$BATTERY"`
CHARGE=`awk -F'[,%] ' '{print $2}' <<< "$BATTERY" | tr -d "%"`
TIME=`awk -F', ' '{print $3}' <<< "$BATTERY" | cut -d " " -f 1 | cut -d: -f1-2`
case "$STATUS" in
2020-07-27 01:16:19 +04:00
Full) ;& "Not charging") icon=; TEXT="FULL"; status=0
2020-02-17 17:00:59 +04:00
;;
Charging)
TEXT="$CHARGE% ($TIME)"
status=0
case $CHARGE in
2020-07-27 01:16:19 +04:00
[2-3]*) icon=;;
[4-5]*) icon=;;
[6-7]*) icon=;;
[8-9]*) icon=;;
100) icon=;;
*) icon=;;
2020-02-17 17:00:59 +04:00
esac
;;
Discharging)
if [[ $CHARGE -gt ${toString low_threshold} ]]
then
status=0
else
status=33
fi
TEXT="$CHARGE% ($TIME)";
case $CHARGE in
2020-07-27 01:16:19 +04:00
1?) icon=;;
2?) icon=;;
3?) icon=;;
4?) icon=;;
5?) icon=;;
6?) icon=;;
7?) icon=;;
8?) icon=;;
9?) icon=;;
100) icon=;;
*) ;;
2020-02-17 17:00:59 +04:00
esac
;;
esac
[[ -n $BLOCK_BUTTON ]] && text=" $TEXT"
echo "<span font=\"${iconfont}\">$icon</span>$text"
exit $status
''