From 17750477e4a423b970dc393a2506901811e0bc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Wed, 9 Jan 2013 00:47:05 +0100 Subject: [PATCH] Optimize _lp_battery: no sed --- liquidprompt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/liquidprompt b/liquidprompt index e5a1c2e..98c46d1 100755 --- a/liquidprompt +++ b/liquidprompt @@ -746,8 +746,10 @@ _lp_battery() [[ "$LP_ENABLE_BATT" != 1 ]] && return local acpi acpi="$(acpi --battery 2>/dev/null)" - local bat - bat=$( echo $acpi | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/") + # Extract the battery load value in percent + # First, remove the beginning of the line... + local bat="${acpi#Battery *, }" + bat="${bat%%%*}" # remove everything starting at '%' if [[ -z "${bat}" ]] ; then # not battery level found