2022-09-01 23:10:23 +04:00
|
|
|
{ upower, gnugrep, coreutils-full, lib, bash, iconfont, low_threshold ? 10, ... }: ''
|
2020-02-17 17:00:59 +04:00
|
|
|
#!${bash}/bin/bash
|
2022-09-01 23:10:23 +04:00
|
|
|
PATH=$PATH:${lib.makeBinPath [ gnugrep upower coreutils-full ]}
|
2021-09-26 16:27:02 +04:00
|
|
|
readarray -t DEVICES <<< "$(${upower}/bin/upower -e | grep -v "DisplayDevice$")"
|
|
|
|
|
|
|
|
DELIM=""
|
|
|
|
STATUS=0
|
|
|
|
|
|
|
|
for dev in "''${DEVICES[@]}"; do
|
|
|
|
INFO="$(${upower}/bin/upower -i "$dev")"
|
|
|
|
PERCENTAGE="$(echo "$INFO" | grep 'percentage:' | grep -o '[[:digit:]]*')"
|
|
|
|
if [ -n "$PERCENTAGE" ]; then
|
2021-09-27 15:17:26 +04:00
|
|
|
TIME="$(echo "$INFO" | grep 'time to' | tr -s ' ' | cut -d' ' -f5-6)"
|
2021-09-26 16:27:02 +04:00
|
|
|
STATE="$(echo "$INFO" | grep 'state:' | tr -s ' ' | cut -d' ' -f3)"
|
|
|
|
if [[ "x$STATE" == "xfully-charged" ]] || [[ "x$STATE" == "xcharging" ]]; then
|
|
|
|
case $PERCENTAGE in
|
2022-02-03 23:15:57 +04:00
|
|
|
[0-9]|1[0-9]) icon=;;
|
|
|
|
[2-3][0-9]) icon=;;
|
|
|
|
[4-5][0-9]) icon=;;
|
|
|
|
[6-7][0-9]) icon=;;
|
|
|
|
[8-9][0-9]) icon=;;
|
2021-09-26 16:27:02 +04:00
|
|
|
100) icon=;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
if [[ "$PERCENTAGE" -lt ${toString low_threshold} ]]; then
|
|
|
|
STATUS=33
|
|
|
|
fi
|
|
|
|
case $PERCENTAGE in
|
2022-02-04 13:55:46 +04:00
|
|
|
[0-9]) icon=;;
|
|
|
|
1[0-9]) icon=;;
|
|
|
|
2[0-9]) icon=;;
|
|
|
|
3[0-9]) icon=;;
|
|
|
|
4[0-9]) icon=;;
|
|
|
|
5[0-9]) icon=;;
|
|
|
|
6[0-9]) icon=;;
|
|
|
|
7[0-9]) icon=;;
|
|
|
|
8[0-9]) icon=;;
|
|
|
|
9[0-9]) icon=;;
|
2021-09-26 16:27:02 +04:00
|
|
|
100) icon=;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
if [ -n "$DELIM" ]; then
|
|
|
|
echo -n "| "
|
|
|
|
else
|
|
|
|
DELIM="yes"
|
|
|
|
fi
|
|
|
|
echo -n "<span font=\"${iconfont}\">"
|
|
|
|
if echo "$INFO" | grep 'native-path:' | grep bluez > /dev/null; then
|
|
|
|
echo -n ""
|
|
|
|
fi
|
|
|
|
echo -n "$icon</span>"
|
|
|
|
if [ -n "$BLOCK_BUTTON" ]; then
|
|
|
|
echo -n " $PERCENTAGE% "
|
|
|
|
if [ -n "$TIME" ]; then echo -n "($TIME) "; fi
|
|
|
|
fi
|
2020-02-17 17:00:59 +04:00
|
|
|
fi
|
2021-09-26 16:27:02 +04:00
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
exit "$STATUS"
|
2020-02-17 17:00:59 +04:00
|
|
|
''
|