From 9f4a8a765604f3468d84b386b6378b19ce0b0a37 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Fri, 23 Jun 2023 14:14:53 +0200 Subject: [PATCH] polybar: Improve headset battery script --- home-manager/modules/polybar/default.nix | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/home-manager/modules/polybar/default.nix b/home-manager/modules/polybar/default.nix index 7659af9..cbd6936 100644 --- a/home-manager/modules/polybar/default.nix +++ b/home-manager/modules/polybar/default.nix @@ -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