Refactor CPU load
Use a single function name for collecting loadavg. Reduces pollution (issue #28). Refactor _lp_load_color: less code but same features.
This commit is contained in:
parent
7f5346f953
commit
2a833475bc
50
liquidprompt
50
liquidprompt
@ -153,27 +153,26 @@ esac
|
|||||||
|
|
||||||
|
|
||||||
# get current load
|
# get current load
|
||||||
|
case "$LP_OS" in
|
||||||
_lp_load_Linux()
|
Linux)
|
||||||
{
|
_lp_cpu_load () {
|
||||||
local load
|
local load eol
|
||||||
load=$(awk '{print $1}' /proc/loadavg)
|
read load eol < /proc/loadavg
|
||||||
echo -n "$load"
|
echo "$load"
|
||||||
}
|
}
|
||||||
|
;;
|
||||||
_lp_load_FreeBSD()
|
FreeBSD)
|
||||||
{
|
_lp_cpu_load () {
|
||||||
local load
|
local bol load eol
|
||||||
load=$(LANG=C sysctl -n vm.loadavg | awk '{print $2}')
|
read bol load eol < $<( LANG=C sysctl -n vm.loadavg )
|
||||||
echo -n "$load"
|
echo "$load"
|
||||||
}
|
}
|
||||||
|
;;
|
||||||
_lp_load_SunOS()
|
SunOS)
|
||||||
{
|
_lp_cpu_load () {
|
||||||
local load
|
LANG=C uptime | awk '{print substr($10,0,length($10))}'
|
||||||
load=$(LANG=C uptime | awk '{print substr($10,0,length($10))}')
|
}
|
||||||
echo -n "$load"
|
esac
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
@ -787,14 +786,9 @@ _lp_load_color()
|
|||||||
# Then we have to choose the values at which the colours switch, with
|
# Then we have to choose the values at which the colours switch, with
|
||||||
# anything past yellow being pretty important.
|
# anything past yellow being pretty important.
|
||||||
|
|
||||||
local loadval
|
|
||||||
local load
|
local load
|
||||||
loadval=$(_lp_load_$LP_OS)
|
load="$(_lp_cpu_load | sed 's/\.//g;s/^0*//g' )"
|
||||||
load=$(echo $loadval | sed 's/\.//g;s/^0*//g' )
|
let "load=${load:-0}/$_lp_CPUNUM"
|
||||||
if [[ -z "$load" ]] ; then
|
|
||||||
load=0
|
|
||||||
fi
|
|
||||||
let "load=$load/$_lp_CPUNUM"
|
|
||||||
|
|
||||||
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
|
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
|
||||||
then
|
then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user