From 13a7844f5703b5d4ba38a13611b139f7e6f982ad Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 18 Oct 2020 00:05:46 +0100 Subject: [PATCH] add temp icons & colours --- cpu.tmux | 6 ++++++ scripts/cpu_temp_bg_color.sh | 37 +++++++++++++++++++++++++++++++++ scripts/cpu_temp_fg_color.sh | 37 +++++++++++++++++++++++++++++++++ scripts/cpu_temp_icon.sh | 40 ++++++++++++++++++++++++++++++++++++ scripts/helpers.sh | 13 ++++++++++++ 5 files changed, 133 insertions(+) create mode 100755 scripts/cpu_temp_bg_color.sh create mode 100755 scripts/cpu_temp_fg_color.sh create mode 100755 scripts/cpu_temp_icon.sh diff --git a/cpu.tmux b/cpu.tmux index ad1d0f1..4098aca 100755 --- a/cpu.tmux +++ b/cpu.tmux @@ -22,6 +22,9 @@ cpu_interpolation=( "\#{gram_bg_color}" "\#{gram_fg_color}" "\#{cpu_temp}" + "\#{cpu_temp_icon}" + "\#{cpu_temp_bg_color}" + "\#{cpu_temp_fg_color}" ) cpu_commands=( "#($CURRENT_DIR/scripts/cpu_percentage.sh)" @@ -41,6 +44,9 @@ cpu_commands=( "#($CURRENT_DIR/scripts/gram_bg_color.sh)" "#($CURRENT_DIR/scripts/gram_fg_color.sh)" "#($CURRENT_DIR/scripts/cpu_temp.sh)" + "#($CURRENT_DIR/scripts/cpu_temp_icon.sh)" + "#($CURRENT_DIR/scripts/cpu_temp_bg_color.sh)" + "#($CURRENT_DIR/scripts/cpu_temp_fg_color.sh)" ) set_tmux_option() { diff --git a/scripts/cpu_temp_bg_color.sh b/scripts/cpu_temp_bg_color.sh new file mode 100755 index 0000000..7cabaa2 --- /dev/null +++ b/scripts/cpu_temp_bg_color.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +cpu_temp_low_bg_color="" +cpu_temp_medium_bg_color="" +cpu_temp_high_bg_color="" + +cpu_temp_low_default_bg_color="#[bg=green]" +cpu_temp_medium_default_bg_color="#[bg=yellow]" +cpu_temp_high_default_bg_color="#[bg=red]" + +get_bg_color_settings() { + cpu_temp_low_bg_color=$(get_tmux_option "@cpu_temp_low_bg_color" "$cpu_temp_low_default_bg_color") + cpu_temp_medium_bg_color=$(get_tmux_option "@cpu_temp_medium_bg_color" "$cpu_temp_medium_default_bg_color") + cpu_temp_high_bg_color=$(get_tmux_option "@cpu_temp_high_bg_color" "$cpu_temp_high_default_bg_color") +} + +print_bg_color() { + local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//') + local cpu_temp_status=$(temp_status $cpu_temp) + if [ $cpu_temp_status == "low" ]; then + echo "$cpu_temp_low_bg_color" + elif [ $cpu_temp_status == "medium" ]; then + echo "$cpu_temp_medium_bg_color" + elif [ $cpu_temp_status == "high" ]; then + echo "$cpu_temp_high_bg_color" + fi +} + +main() { + get_bg_color_settings + print_bg_color +} +main diff --git a/scripts/cpu_temp_fg_color.sh b/scripts/cpu_temp_fg_color.sh new file mode 100755 index 0000000..eff31b8 --- /dev/null +++ b/scripts/cpu_temp_fg_color.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +cpu_temp_low_fg_color="" +cpu_temp_medium_fg_color="" +cpu_temp_high_fg_color="" + +cpu_temp_low_default_fg_color="#[bg=green]" +cpu_temp_medium_default_fg_color="#[bg=yellow]" +cpu_temp_high_default_fg_color="#[bg=red]" + +get_fg_color_settings() { + cpu_temp_low_fg_color=$(get_tmux_option "@cpu_temp_low_fg_color" "$cpu_temp_low_default_fg_color") + cpu_temp_medium_fg_color=$(get_tmux_option "@cpu_temp_medium_fg_color" "$cpu_temp_medium_default_fg_color") + cpu_temp_high_fg_color=$(get_tmux_option "@cpu_temp_high_fg_color" "$cpu_temp_high_default_fg_color") +} + +print_fg_color() { + local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//') + local cpu_temp_status=$(temp_status $cpu_temp) + if [ $cpu_temp_status == "low" ]; then + echo "$cpu_temp_low_fg_color" + elif [ $cpu_temp_status == "medium" ]; then + echo "$cpu_temp_medium_fg_color" + elif [ $cpu_temp_status == "high" ]; then + echo "$cpu_temp_high_fg_color" + fi +} + +main() { + get_fg_color_settings + print_fg_color +} +main diff --git a/scripts/cpu_temp_icon.sh b/scripts/cpu_temp_icon.sh new file mode 100755 index 0000000..170c73f --- /dev/null +++ b/scripts/cpu_temp_icon.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +# script global variables +cpu_temp_low_icon="" +cpu_temp_medium_icon="" +cpu_temp_high_icon="" + +cpu_temp_low_default_icon="=" +cpu_temp_medium_default_icon="≡" +cpu_temp_high_default_icon="≣" + +# icons are set as script global variables +get_icon_settings() { + cpu_temp_low_icon=$(get_tmux_option "@cpu_temp_low_icon" "$cpu_temp_low_default_icon") + cpu_temp_medium_icon=$(get_tmux_option "@cpu_temp_medium_icon" "$cpu_temp_medium_default_icon") + cpu_temp_high_icon=$(get_tmux_option "@cpu_temp_high_icon" "$cpu_temp_high_default_icon") +} + +print_icon() { + local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//') + local cpu_temp_status=$(temp_status $cpu_temp) + if [ $cpu_temp_status == "low" ]; then + echo "$cpu_temp_low_icon" + elif [ $cpu_temp_status == "medium" ]; then + echo "$cpu_temp_medium_icon" + elif [ $cpu_temp_status == "high" ]; then + echo "$cpu_temp_high_icon" + fi +} + +main() { + get_icon_settings + local cpu_temp_icon=$(print_icon "$1") + echo "$cpu_temp_icon" +} +main diff --git a/scripts/helpers.sh b/scripts/helpers.sh index a38b27a..a05ff48 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -55,6 +55,19 @@ load_status() { fi } +temp_status() { + local temp=$1 + cpu_medium_thresh=$(get_tmux_option "@cpu_temp_medium_thresh" "80") + cpu_high_thresh=$(get_tmux_option "@cpu_temp_high_thresh" "90") + if fcomp $cpu_temp_high_thresh $temp; then + echo "high" + elif fcomp $cpu_temp_medium_thresh $temp && fcomp $temp $cpu_temp_high_thresh; then + echo "medium" + else + echo "low" + fi +} + cpus_number() { if is_linux; then nproc