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
|
||||
|
||||
_lp_load_Linux()
|
||||
{
|
||||
local load
|
||||
load=$(awk '{print $1}' /proc/loadavg)
|
||||
echo -n "$load"
|
||||
}
|
||||
|
||||
_lp_load_FreeBSD()
|
||||
{
|
||||
local load
|
||||
load=$(LANG=C sysctl -n vm.loadavg | awk '{print $2}')
|
||||
echo -n "$load"
|
||||
}
|
||||
|
||||
_lp_load_SunOS()
|
||||
{
|
||||
local load
|
||||
load=$(LANG=C uptime | awk '{print substr($10,0,length($10))}')
|
||||
echo -n "$load"
|
||||
}
|
||||
case "$LP_OS" in
|
||||
Linux)
|
||||
_lp_cpu_load () {
|
||||
local load eol
|
||||
read load eol < /proc/loadavg
|
||||
echo "$load"
|
||||
}
|
||||
;;
|
||||
FreeBSD)
|
||||
_lp_cpu_load () {
|
||||
local bol load eol
|
||||
read bol load eol < $<( LANG=C sysctl -n vm.loadavg )
|
||||
echo "$load"
|
||||
}
|
||||
;;
|
||||
SunOS)
|
||||
_lp_cpu_load () {
|
||||
LANG=C uptime | awk '{print substr($10,0,length($10))}'
|
||||
}
|
||||
esac
|
||||
|
||||
|
||||
#################
|
||||
@ -787,14 +786,9 @@ _lp_load_color()
|
||||
# Then we have to choose the values at which the colours switch, with
|
||||
# anything past yellow being pretty important.
|
||||
|
||||
local loadval
|
||||
local load
|
||||
loadval=$(_lp_load_$LP_OS)
|
||||
load=$(echo $loadval | sed 's/\.//g;s/^0*//g' )
|
||||
if [[ -z "$load" ]] ; then
|
||||
load=0
|
||||
fi
|
||||
let "load=$load/$_lp_CPUNUM"
|
||||
load="$(_lp_cpu_load | sed 's/\.//g;s/^0*//g' )"
|
||||
let "load=${load:-0}/$_lp_CPUNUM"
|
||||
|
||||
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
|
||||
then
|
||||
|
Loading…
x
Reference in New Issue
Block a user