Optimize _lp_load_color

This commit is contained in:
Olivier Mengué 2013-05-14 01:15:04 +02:00
parent ea1c897aef
commit e7ae332fc8

View File

@ -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
}