mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-16 09:50:06 +00:00
Fix average selection in load segment.
Removed duplicate code selecting which load average to use. Fixed load average selection being in OSX/BSD part of if, making it not work on non OSX/BSD systems. Optimized actually getting the load average.
This commit is contained in:
parent
c6c405955e
commit
2c388b6c80
1 changed files with 28 additions and 21 deletions
|
@ -932,13 +932,14 @@ prompt_vpn_ip() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_default POWERLEVEL9K_LOAD_WHICH 5
|
||||||
prompt_load() {
|
prompt_load() {
|
||||||
# The load segment can have three different states
|
# The load segment can have three different states
|
||||||
local current_state="unknown"
|
local current_state="unknown"
|
||||||
|
local load_select=2
|
||||||
|
local load_avg
|
||||||
local cores
|
local cores
|
||||||
|
|
||||||
set_default POWERLEVEL9K_LOAD_WHICH 5
|
|
||||||
|
|
||||||
typeset -AH load_states
|
typeset -AH load_states
|
||||||
load_states=(
|
load_states=(
|
||||||
'critical' 'red'
|
'critical' 'red'
|
||||||
|
@ -946,32 +947,38 @@ prompt_load() {
|
||||||
'normal' 'green'
|
'normal' 'green'
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then
|
case "$POWERLEVEL9K_LOAD_WHICH" in
|
||||||
|
1)
|
||||||
|
load_select=1
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
load_select=2
|
||||||
|
;;
|
||||||
|
15)
|
||||||
|
load_select=3
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then
|
case "$OS" in
|
||||||
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 1p)
|
OSX|BSD)
|
||||||
elif [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 5 ]]; then
|
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p)
|
||||||
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p)
|
if [[ "$OS" == "OSX" ]]; then
|
||||||
else
|
cores=$(sysctl -n hw.logicalcpu)
|
||||||
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p)
|
else
|
||||||
fi
|
cores=$(sysctl -n hw.ncpu)
|
||||||
|
fi
|
||||||
if [[ "$OS" == "OSX" ]]; then
|
;;
|
||||||
cores=$(sysctl -n hw.logicalcpu)
|
*)
|
||||||
else
|
load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
|
||||||
cores=$(sysctl -n hw.ncpu)
|
cores=$(nproc)
|
||||||
fi
|
esac
|
||||||
else
|
|
||||||
load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
|
|
||||||
cores=$(nproc)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Replace comma
|
# Replace comma
|
||||||
load_avg=${load_avg//,/.}
|
load_avg=${load_avg//,/.}
|
||||||
|
|
||||||
if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
|
if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
|
||||||
current_state="critical"
|
current_state="critical"
|
||||||
elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
|
elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
|
||||||
current_state="warning"
|
current_state="warning"
|
||||||
else
|
else
|
||||||
current_state="normal"
|
current_state="normal"
|
||||||
|
|
Loading…
Reference in a new issue