#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG 7.5				#
#							#
# Licensed under GNU LESSER GENERAL PUBLIC LICENSE v3	#
#							#
# Copyright 2007 - 2008 Christopher Bratusek		#
#							#
#########################################################

NICE_IGNORE=20

t="0"
while
read cpu ni;
do
if [[ $ni -le $NICE_IGNORE ]]; then
	t="$t + $cpu"
fi
if [[ ${cpu%%.*} -eq 0 ]]; then
break
fi
done < <(ps -Ao "%cpu= ni="| sort -r)
cpu=$(echo "$t" | bc)
if [[ ! "${cpu#.}x" = "${cpu}x" ]]; then
	cpu="0${cpu}"
fi
cpu=${cpu%%.*}
if [[ $cpu -gt 100 ]]; then
cpu=100
fi

if [[ $cpu -lt 16 ]]; then
	color=$(bs-ng-parse-echo $iceblue)
elif [[ $cpu -lt 26 ]]; then
	color=$(bs-ng-parse-echo $turqoise)
elif [[ $cpu -lt 41 ]]; then
        color=$(bs-ng-parse-echo $smoothgreen)
elif [[ $cpu -lt 61 ]]; then
	color=$(bs-ng-parse-echo $green)
elif [[ $cpu -lt 81 ]]; then	
	color=$(bs-ng-parse-echo $yellow)
else	color=$(bs-ng-parse-echo $red)
fi

if [[ $cpu -lt 10 ]]; then
	prepend=00
elif [[ $cpu -lt 100 ]]; then
	prepend=0
fi

if [[ $enabcol == true ]]; then
	echo -e "$color$prepend$cpu"
else	echo $prepend$cpu
fi
