polybar: Improve headset battery script

This commit is contained in:
Erwin Boskma 2023-06-23 14:14:53 +02:00
parent 6040e83cd9
commit 9f4a8a7656
Signed by: erwin
SSH key fingerprint: SHA256:3F6Cm6I3erRqlBwEghZWAQl6eS5WrGTX1Vs/Evec1lQ

View file

@ -44,16 +44,21 @@ with lib; let
};
headset-battery = pkgs.writeShellScript "headset-battery" ''
battery_level=$(${pkgs.headsetcontrol}/bin/headsetcontrol -c -b)
battery_level=$(${pkgs.headsetcontrol}/bin/headsetcontrol -c -b 2> /dev/null)
if [[ $? -ne 0 ]]; then
printf "󰂑"
exit
fi
battery_icons=(󰁺 󰁻 󰁼 󰁽 󰁾 󰁿 󰂀 󰂁 󰂂 󰁹 )
battery_charging="󰂄"
if [ "''${battery_level}" -eq -1 ]; then
if [[ "''${battery_level}" -eq -1 ]]; then
printf "%s " "''${battery_charging}"
else
idx=$(((battery_level / 10)))
if [ "''${idx}" -eq 10 ]; then
if [[ "''${idx}" -eq 10 ]]; then
idx=9
fi