From c1d150ad3513cb6411286463b847688dfee045c6 Mon Sep 17 00:00:00 2001 From: Norbert Szivos Date: Sun, 9 Feb 2020 20:56:44 +0100 Subject: [PATCH] Fix battery percentage output when using upower Upower output was 98.4789% which mess up the icon and graph view as well. --- scripts/battery_percentage.sh | 2 +- scripts/helpers.sh | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) mode change 100644 => 100755 scripts/helpers.sh diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index eb56e0e..68ef5bd 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -18,7 +18,7 @@ print_battery_percentage() { fi local percentage=$(upower -i $battery | awk '/percentage:/ {print $2}') if [ "$percentage" ]; then - echo ${percentage%.*%} + echo "$(float2int $percentage)%" return fi local energy diff --git a/scripts/helpers.sh b/scripts/helpers.sh old mode 100644 new mode 100755 index 067c120..e37d399 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -48,3 +48,14 @@ battery_status() { fi fi } + +float2int() { + local float="$1" + if [[ $float =~ "," ]]; then + echo ${float%,*} + elif [[ $float =~ "." ]]; then + echo ${float%.*} + else + echo ${float//%} + fi +}