aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorTadek Teleżyński <tadekte@gmail.com>2017-08-17 22:54:26 +0300
committerTadek Teleżyński <tadekte@gmail.com>2017-08-17 22:54:26 +0300
commit582edf200c825abbc75ec8a643b2e7ecdbd59561 (patch)
tree44c6ab86ec6b11a3a3022276a1e76ffde4f6145c /powerlevel9k.zsh-theme
parent9f4faf7f21a992f32114f134dfb0737657241b37 (diff)
Add average choice to load extension
This commit adds a functionality to choose if one wants to see 1, 5 or 15 minutes average. Resolves issue #604
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme23
1 files changed, 17 insertions, 6 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3c34f0bb..b03a9374 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -937,6 +937,8 @@ prompt_load() {
local current_state="unknown"
local cores
+ set_default POWERLEVEL9K_LOAD_WHICH 5
+
typeset -AH load_states
load_states=(
'critical' 'red'
@@ -945,31 +947,40 @@ prompt_load() {
)
if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then
- load_avg_1min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1)
+
+ if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then
+ 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
+ load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p)
+ else
+ load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p)
+ fi
+
if [[ "$OS" == "OSX" ]]; then
cores=$(sysctl -n hw.logicalcpu)
else
cores=$(sysctl -n hw.ncpu)
fi
else
- load_avg_1min=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
+ load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
cores=$(nproc)
fi
# Replace comma
- load_avg_1min=${load_avg_1min//,/.}
+ load_avg=${load_avg//,/.}
- if [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
+ if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
current_state="critical"
- elif [[ "$load_avg_1min" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
+elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then
current_state="warning"
else
current_state="normal"
fi
- "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_1min" 'LOAD_ICON'
+ "$1_prompt_segment" "${0}_${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg" 'LOAD_ICON'
}
+
# Node version
prompt_node_version() {
local node_version=$(node -v 2>/dev/null)