From b50970f634d16d4c59154acf126c69602f343d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 13 May 2013 20:23:55 +0200 Subject: [PATCH] Optimize _lp_color_map using arithmetic comparisons --- liquidprompt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/liquidprompt b/liquidprompt index 46b887b..1e14ad4 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1127,28 +1127,28 @@ _lp_battery_color() } _lp_color_map() { - if [[ $1 -ge 0 ]] && [[ $1 -lt 20 ]] ; then + local -i load + load=$1 + if (( load < 20 )); then echo -ne "${LP_COLORMAP_0}" - elif [[ $1 -ge 20 ]] && [[ $1 -lt 40 ]] ; then + elif (( load < 40 )); then echo -ne "${LP_COLORMAP_1}" - elif [[ $1 -ge 40 ]] && [[ $1 -lt 60 ]] ; then + elif (( load < 60 )); then echo -ne "${LP_COLORMAP_2}" - elif [[ $1 -ge 60 ]] && [[ $1 -lt 80 ]] ; then + elif (( load < 80 )); then echo -ne "${LP_COLORMAP_3}" - elif [[ $1 -ge 80 ]] && [[ $1 -lt 100 ]] ; then + elif (( load < 100 )); then echo -ne "${LP_COLORMAP_4}" - elif [[ $1 -ge 100 ]] && [[ $1 -lt 120 ]] ; then + elif (( load < 120 )); then echo -ne "${LP_COLORMAP_5}" - elif [[ $1 -ge 120 ]] && [[ $1 -lt 140 ]] ; then + elif (( load < 140 )); then echo -ne "${LP_COLORMAP_6}" - elif [[ $1 -ge 140 ]] && [[ $1 -lt 160 ]] ; then + elif (( load < 160 )); then echo -ne "${LP_COLORMAP_7}" - elif [[ $1 -ge 160 ]] && [[ $1 -lt 180 ]] ; then + elif (( load < 180 )) ; then echo -ne "${LP_COLORMAP_8}" - elif [[ $1 -ge 180 ]] ; then + else # (( load >= 180 )) echo -ne "${LP_COLORMAP_9}" - else - echo -ne "${LP_COLORMAP_0}" fi }