Cleanup of the `load` segment.
This commit is contained in:
parent
d0a76d721c
commit
cdf08734db
|
@ -492,6 +492,14 @@ prompt_ip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_load() {
|
prompt_load() {
|
||||||
|
# The load segment can have three different states
|
||||||
|
local current_state="unknown"
|
||||||
|
typeset -AH load_states
|
||||||
|
load_states=(
|
||||||
|
'critical' 'red'
|
||||||
|
'warning' 'yellow'
|
||||||
|
'normal' 'green'
|
||||||
|
)
|
||||||
if [[ "$OS" == "OSX" ]]; then
|
if [[ "$OS" == "OSX" ]]; then
|
||||||
load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1)
|
load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1)
|
||||||
else
|
else
|
||||||
|
@ -502,17 +510,14 @@ prompt_load() {
|
||||||
load_avg_5min=${load_avg_5min//,/.}
|
load_avg_5min=${load_avg_5min//,/.}
|
||||||
|
|
||||||
if [[ "$load_avg_5min" -gt 10 ]]; then
|
if [[ "$load_avg_5min" -gt 10 ]]; then
|
||||||
BACKGROUND_COLOR="red"
|
current_state="critical"
|
||||||
FUNCTION_SUFFIX="_CRITICAL"
|
|
||||||
elif [[ "$load_avg_5min" -gt 3 ]]; then
|
elif [[ "$load_avg_5min" -gt 3 ]]; then
|
||||||
BACKGROUND_COLOR="yellow"
|
current_state="warning"
|
||||||
FUNCTION_SUFFIX="_WARNING"
|
|
||||||
else
|
else
|
||||||
BACKGROUND_COLOR="green"
|
current_state="normal"
|
||||||
FUNCTION_SUFFIX="_NORMAL"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON'
|
"$1_prompt_segment" "${0}${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Node version
|
# Node version
|
||||||
|
|
Loading…
Reference in New Issue