summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorRichard Tippl <richard.tippl@gmail.com>2017-08-27 23:42:52 +0300
committerRichard Tippl <richard.tippl@gmail.com>2017-08-27 23:42:52 +0300
commit2c388b6c809189551eab94a8a43346987fdfc330 (patch)
treebfaf49a991aaf5cbe483f43d98a982bae63dd285 /powerlevel9k.zsh-theme
parentc6c405955e56475cbdd9347ef259c2d4229171c4 (diff)
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.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme49
1 files changed, 28 insertions, 21 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index b03a9374..5aa280c6 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -932,13 +932,14 @@ prompt_vpn_ip() {
done
}
+set_default POWERLEVEL9K_LOAD_WHICH 5
prompt_load() {
# The load segment can have three different states
local current_state="unknown"
+ local load_select=2
+ local load_avg
local cores
- set_default POWERLEVEL9K_LOAD_WHICH 5
-
typeset -AH load_states
load_states=(
'critical' 'red'
@@ -946,32 +947,38 @@ prompt_load() {
'normal' 'green'
)
- if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then
-
- 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
+ case "$POWERLEVEL9K_LOAD_WHICH" in
+ 1)
+ load_select=1
+ ;;
+ 5)
+ load_select=2
+ ;;
+ 15)
+ load_select=3
+ ;;
+ esac
- if [[ "$OS" == "OSX" ]]; then
- cores=$(sysctl -n hw.logicalcpu)
- else
- cores=$(sysctl -n hw.ncpu)
- fi
- else
- load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1)
- cores=$(nproc)
- fi
+ 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
+ cores=$(sysctl -n hw.logicalcpu)
+ else
+ cores=$(sysctl -n hw.ncpu)
+ fi
+ ;;
+ *)
+ load_avg=$(cut -d" " -f${load_select} /proc/loadavg)
+ cores=$(nproc)
+ esac
# Replace comma
load_avg=${load_avg//,/.}
if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then
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"
else
current_state="normal"