From 2dbd75cadfc68ff656bf42d3c91304a64be37d61 Mon Sep 17 00:00:00 2001 From: adrianmihalko Date: Wed, 22 Dec 2021 23:11:09 +0100 Subject: [PATCH] Add load average support --- INSTALL.md | 6 ++++++ README.md | 2 +- scripts/cpu_info.sh | 27 ++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index f6e915e..c216db3 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -119,6 +119,12 @@ Customize label set -g @dracula-cpu-usage-label "CPU" ``` +Show load average instead of percentage + +```bash +set -g @dracula-cpu-display-load true +``` + #### gpu-usage options Customize label diff --git a/README.md b/README.md index eef0aaa..f4b3c51 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul * Git branch and status * Battery percentage and AC power connection status * Refresh rate control -* CPU usage +* CPU usage (percentage or load average) * RAM usage * GPU usage * Color code based on if prefix is active or not diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 0cd396b..41b49c1 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -27,13 +27,30 @@ get_percent() esac } -main() -{ +get_load() { + case $(uname -s) in + Linux | Darwin) + loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g') + echo $loadavg + ;; + + CYGWIN* | MINGW32* | MSYS* | MINGW*) + # TODO - windows compatability + ;; + esac +} + +main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) - cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") - cpu_percent=$(get_percent) - echo "$cpu_label $cpu_percent" + cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false) + if [ "$cpu_load" = true ]; then + echo "$(get_load)" + else + cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") + cpu_percent=$(get_percent) + echo "$cpu_label $cpu_percent" + fi sleep $RATE }