1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-27 06:10:09 +00:00

Merge pull request #608 from tippl/fix_load_segment

Fix average selection in load segment.
This commit is contained in:
Ben Hilburn 2017-08-27 20:39:16 -04:00 committed by GitHub
commit 688f6203b4

View file

@ -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,25 +947,31 @@ prompt_load() {
'normal' 'green' 'normal' 'green'
) )
if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then case "$POWERLEVEL9K_LOAD_WHICH" in
1)
if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then load_select=1
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 1p) ;;
elif [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 5 ]]; then 5)
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p) load_select=2
else ;;
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p) 15)
fi load_select=3
;;
esac
case "$OS" in
OSX|BSD)
load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p)
if [[ "$OS" == "OSX" ]]; then if [[ "$OS" == "OSX" ]]; then
cores=$(sysctl -n hw.logicalcpu) cores=$(sysctl -n hw.logicalcpu)
else else
cores=$(sysctl -n hw.ncpu) cores=$(sysctl -n hw.ncpu)
fi fi
else ;;
load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) *)
load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
cores=$(nproc) cores=$(nproc)
fi esac
# Replace comma # Replace comma
load_avg=${load_avg//,/.} load_avg=${load_avg//,/.}