mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-12 19:18:28 +02:00
speed up load prompt
This commit is contained in:
parent
b92d510882
commit
f4df65c172
@ -1055,58 +1055,43 @@ prompt_laravel_version() {
|
|||||||
# Segment to display load
|
# Segment to display load
|
||||||
set_default -i POWERLEVEL9K_LOAD_WHICH 5
|
set_default -i POWERLEVEL9K_LOAD_WHICH 5
|
||||||
prompt_load() {
|
prompt_load() {
|
||||||
local ROOT_PREFIX="${4}"
|
local bucket=2
|
||||||
# The load segment can have three different states
|
case $POWERLEVEL9K_LOAD_WHICH in
|
||||||
local current_state="unknown"
|
1) bucket=1;;
|
||||||
local load_select=2
|
5) bucket=2;;
|
||||||
local load_avg
|
15) bucket=3;;
|
||||||
local cores
|
|
||||||
|
|
||||||
typeset -AH load_states
|
|
||||||
load_states=(
|
|
||||||
'critical' 'red'
|
|
||||||
'warning' 'yellow'
|
|
||||||
'normal' 'green'
|
|
||||||
)
|
|
||||||
|
|
||||||
case "$POWERLEVEL9K_LOAD_WHICH" in
|
|
||||||
1)
|
|
||||||
load_select=1
|
|
||||||
;;
|
|
||||||
5)
|
|
||||||
load_select=2
|
|
||||||
;;
|
|
||||||
15)
|
|
||||||
load_select=3
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$OS" in
|
local load
|
||||||
|
case $OS in
|
||||||
OSX|BSD)
|
OSX|BSD)
|
||||||
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p)
|
(( $+commands[sysctl] )) || return
|
||||||
if [[ "$OS" == "OSX" ]]; then
|
load=$(sysctl -n vm.loadavg) || return
|
||||||
cores=$(sysctl -n hw.logicalcpu)
|
load=${${(A)=load}[bucket+1]//,/.}
|
||||||
else
|
;;
|
||||||
cores=$(sysctl -n hw.ncpu)
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
load_avg=$(cut -d" " -f${load_select} ${ROOT_PREFIX}/proc/loadavg)
|
_p9k_read_file /proc/loadavg || return
|
||||||
cores=$(nproc)
|
load=${${(A)=_P9K_RETVAL}[bucket]//,/.}
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Replace comma
|
if (( ! $+_P9K_NUM_CPUS )); then
|
||||||
load_avg=${load_avg//,/.}
|
case $OS in
|
||||||
|
OSX) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(sysctl -n hw.logicalcpu) || return;;
|
||||||
if [[ "$load_avg" -gt $((${cores} * 0.7)) ]]; then
|
BSD) (( $+commands[sysctl] )) && _P9K_NUM_CPUS=$(sysctl -n hw.ncpu) || return;;
|
||||||
current_state="critical"
|
*) (( $+commands[nproc] )) && _P9K_NUM_CPUS=$(nproc) || return;;
|
||||||
elif [[ "$load_avg" -gt $((${cores} * 0.5)) ]]; then
|
esac
|
||||||
current_state="warning"
|
|
||||||
else
|
|
||||||
current_state="normal"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" 'LOAD_ICON' 0 '' "$load_avg"
|
if (( load > 0.7 * _P9K_NUM_CPUS )); then
|
||||||
|
local state=critical bg=red
|
||||||
|
elif (( load > 0.5 * _P9K_NUM_CPUS )); then
|
||||||
|
local state=warning bg=yellow
|
||||||
|
else
|
||||||
|
local state=normal bg=green
|
||||||
|
fi
|
||||||
|
|
||||||
|
$1_prompt_segment $0_$state $2 $bg "$DEFAULT_COLOR" LOAD_ICON 0 '' $load
|
||||||
}
|
}
|
||||||
|
|
||||||
function _p9k_cached_cmd_stdout() {
|
function _p9k_cached_cmd_stdout() {
|
||||||
|
Loading…
Reference in New Issue
Block a user