From e7ae332fc805829a542676484244f53012e7b801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 14 May 2013 01:15:04 +0200 Subject: [PATCH] Optimize _lp_load_color --- liquidprompt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/liquidprompt b/liquidprompt index d560f69..c105154 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1174,22 +1174,23 @@ _lp_load_color() [[ "$LP_ENABLE_LOAD" != 1 ]] && return - local load - load="$(_lp_cpu_load | sed 's/\.//g;s/^0*//g' )" - let "load=${load:-0}/$_lp_CPUNUM" + local tmp=$(_lp_cpu_load) + tmp=${tmp/./} # Remove '.' + tmp=${tmp#0} # Remove leading '0' + tmp=${tmp#0} # Remove leading '0', again (ex: 0.09) + local -i load=${tmp:-0}/$_lp_CPUNUM - if [[ $load -ge $LP_LOAD_THRESHOLD ]] - then - local ret="$(_lp_color_map $load) ${LP_MARK_LOAD}" + if (( load > $LP_LOAD_THRESHOLD )); then + local ret="$(_lp_color_map $load)${LP_MARK_LOAD}" - if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then + if [[ "$LP_PERCENTS_ALWAYS" == 1 ]]; then if $_LP_SHELL_bash; then ret="${ret}$load%" else # zsh ret="${ret}$load%%" fi fi - echo -ne "${ret}${NO_COL}" + echo -nE "${ret}${NO_COL}" fi }