diff --git a/README.md b/README.md index 6c35a54..fd24c07 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ This is done by introducing 8 new format strings that can be added to - `#{cpu_percentage}` - will show CPU percentage (averaged across cores) - `#{cpu_bg_color}` - will change the background color based on the CPU percentage - `#{cpu_fg_color}` - will change the foreground color based on the CPU percentage + - `#{load}` - will display your current load averages (1, 5 and 15 minutes) + - `#{load1}` - will display the load average of the last minute + - `#{load5}` - will display the load average of the last 5 minutes + - `#{load15}` - will display the load average of the last 15 minutes - `#{ram_icon}` - will display a RAM status icon - `#{ram_percentage}` - will show RAM percentage (averaged across cores) - `#{ram_bg_color}` - will change the background color based on the RAM percentage @@ -111,6 +115,8 @@ Here are all available options with their default values: @cpu_high_bg_color "#[bg=red]" # background color when cpu is high @cpu_percentage_format "%3.1f%%" # printf format to use to display percentage + +@load_per_cpu_core "false" # if set to "true" the load averages will be divided by the number of CPU cores ``` Same options are valid with `@gpu` diff --git a/cpu.tmux b/cpu.tmux index ef8e41a..b084eaf 100755 --- a/cpu.tmux +++ b/cpu.tmux @@ -13,6 +13,10 @@ cpu_interpolation=( "\#{gpu_icon}" "\#{gpu_bg_color}" "\#{gpu_fg_color}" + "\#{load}" + "\#{load1}" + "\#{load5}" + "\#{load15}" "\#{ram_percentage}" "\#{ram_icon}" "\#{ram_bg_color}" @@ -31,6 +35,10 @@ cpu_commands=( "#($CURRENT_DIR/scripts/gpu_icon.sh)" "#($CURRENT_DIR/scripts/gpu_bg_color.sh)" "#($CURRENT_DIR/scripts/gpu_fg_color.sh)" + "#($CURRENT_DIR/scripts/load.sh)" + "#($CURRENT_DIR/scripts/load.sh 1)" + "#($CURRENT_DIR/scripts/load.sh 5)" + "#($CURRENT_DIR/scripts/load.sh 15)" "#($CURRENT_DIR/scripts/ram_percentage.sh)" "#($CURRENT_DIR/scripts/ram_icon.sh)" "#($CURRENT_DIR/scripts/ram_bg_color.sh)" diff --git a/scripts/load.sh b/scripts/load.sh new file mode 100755 index 0000000..ea0bd13 --- /dev/null +++ b/scripts/load.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +get_number_of_cores(){ + if is_osx + then + sysctl -n hw.ncpu + else + nproc + fi +} + + +print_load() { + local num_cores=1 + local output + + case "$(get_tmux_option "@load_per_cpu_core")" in + true|1|yes) + num_cores=$(get_number_of_cores) + ;; + esac + + output=$(uptime | awk -v num_cores="$num_cores" '{ + sub(/,$/, "", $(NF-2)); + sub(/,$/, "", $(NF-1)); + sub(/,$/, "", $NF); + printf "%.2f %.2f %.2f", $(NF-2)/num_cores, $(NF-1)/num_cores, $NF/num_cores + }') + + case "$1" in + 1) + output="$(awk '{ print $1 }' <<< "$output")" + ;; + 5) + output="$(awk '{ print $2 }' <<< "$output")" + ;; + 15) + output="$(awk '{ print $3 }' <<< "$output")" + ;; + esac + + # Replace commas with dots + echo -n "${output//,/.}" +} + +main() { + print_load "$@" +} + +main "$@"