From ee6343567d2178cd57daa89498868be6ea2ef156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 30 Jun 2014 23:56:49 +0200 Subject: [PATCH] lp_battery_color: optimize colormap code when LP_PERCENT_ALWAYS=1 Better code (less comparisons) for colorization of the battery level percent value. --- liquidprompt | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/liquidprompt b/liquidprompt index f98780f..88e9f14 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1223,26 +1223,27 @@ _lp_battery_color() ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}" if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then - if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 80 ]] ; then # -20 - ret="${ret}${LP_COLORMAP_1}" - elif [[ ${bat} -le 80 ]] && [[ ${bat} -gt 65 ]] ; then # -15 - ret="${ret}${LP_COLORMAP_2}" - elif [[ ${bat} -le 65 ]] && [[ ${bat} -gt 50 ]] ; then # -15 - ret="${ret}${LP_COLORMAP_3}" - elif [[ ${bat} -le 50 ]] && [[ ${bat} -gt 40 ]] ; then # -10 - ret="${ret}${LP_COLORMAP_4}" - elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 30 ]] ; then # … - ret="${ret}${LP_COLORMAP_5}" - elif [[ ${bat} -le 30 ]] && [[ ${bat} -gt 20 ]] ; then - ret="${ret}${LP_COLORMAP_6}" - elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then - ret="${ret}${LP_COLORMAP_7}" - elif [[ ${bat} -le 10 ]] && [[ ${bat} -gt 5 ]] ; then - ret="${ret}${LP_COLORMAP_8}" - elif [[ ${bat} -le 5 ]] && [[ ${bat} -gt 0 ]] ; then + if (( bat <= 0 )); then + ret="${ret}${LP_COLORMAP_0}" + elif (( bat <= 5 )); then # 5 ret="${ret}${LP_COLORMAP_9}" - else - # for debugging purpose + elif (( bat <= 10 )); then # 5 + ret="${ret}${LP_COLORMAP_8}" + elif (( bat <= 20 )); then # 10 + ret="${ret}${LP_COLORMAP_7}" + elif (( bat <= 30 )); then # 10 + ret="${ret}${LP_COLORMAP_6}" + elif (( bat <= 40 )); then # 10 + ret="${ret}${LP_COLORMAP_5}" + elif (( bat <= 50 )); then # 10 + ret="${ret}${LP_COLORMAP_4}" + elif (( bat <= 65 )); then # 15 + ret="${ret}${LP_COLORMAP_3}" + elif (( bat <= 80 )); then # 15 + ret="${ret}${LP_COLORMAP_2}" + elif (( bat < 100 )); then # 20 + ret="${ret}${LP_COLORMAP_1}" + else # >= 100 ret="${ret}${LP_COLORMAP_0}" fi