From 6195f08b8a574acfadad5c92407951adc990f8b7 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 1 Aug 2022 13:27:46 +0200 Subject: [PATCH] screen: added cputemp script and rearranged hardstatus widgets order --- screen/.config/screen/bin/cputemp.sh | 115 +++++++++++++++++++++++++++ screen/.screenrc | 3 +- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 screen/.config/screen/bin/cputemp.sh diff --git a/screen/.config/screen/bin/cputemp.sh b/screen/.config/screen/bin/cputemp.sh new file mode 100755 index 0000000..1ef789f --- /dev/null +++ b/screen/.config/screen/bin/cputemp.sh @@ -0,0 +1,115 @@ +#!/bin/sh +# Returns the temperature of the CPUs. +# The temperature is extracted from the package, if available, otherwise from +# the highest measurement of all cores for each CPU. +# See: https://www.kernel.org/doc/html/latest/hwmon/coretemp.html + +set -e + +while [ $# -gt 0 ] ; do + case "$1" in + "--newline") + newline=1 + ;; + "--unit") + unitsymbol="°C" + ;; + "--color") + case $2 in + "screen") + shift + colorize=1 + colgreen="\005{g}" + colyellow="\005{y}" + colred="\005{r}" + colred_blink="\005{+B r}" + colend="\005{-}" + ;; + "lemonbar") + shift + colorize=1 + # xterm ANSI color palette + colgreen="%{F#00CD00}" + colyellow="%{F#CDCD00}" + colred="%{F#CD0000}" + colred_blink="%{F#000000}%{B#CD0000}" # no blinking available :( + colend="%{F-}" + colbgend="%{B-}" + ;; + "ansi"|""|"--"*) + case "$2" in + "--"*|"") + : # skip if it's a parameter or is empty + ;; + *) + shift + ;; + esac + colorize=1 + colgreen="\033[0;32m" + colyellow="\033[0;33m" + colred="\033[0;31m" + colred_blink="\033[5;31m" + colend="\033[0m" + ;; + *) + printf "Color coding not supported. Aborting...\n" + exit 1 + ;; + esac + ;; + *) + printf "Parameter not recognized. Aborting...\n" + exit 1 + ;; + esac + shift +done + +multi_cpu=0 + +__colorize() { + if [ "$1" -lt 75 ]; then + color="$colgreen" + elif [ "$1" -lt 80 ]; then + color="$colyellow" + elif [ "$1" -lt 85 ]; then + color="$colred" + else + color="$colred_blink" + fi +} + +for cpu in /sys/devices/platform/coretemp.?; do + [ -r "$cpu" ] || continue + for cpu_hwmon in "$cpu"/hwmon/hwmon?; do + is_package=0 + while read -r f_content; do + case "$f_content" in + "Package id "[0-9]) + is_package=1 + ;; + esac + done < "$cpu_hwmon/temp1_label" + cpu_temp="-99" + for core_temp_path in "$cpu_hwmon"/temp?_input; do + while read -r f_content; do + core_temp="${f_content%[0-9][0-9][0-9]}" + [ "$core_temp" -gt $cpu_temp ] && cpu_temp="$core_temp" + done < "$core_temp_path" + [ $is_package = 1 ] && break + done + [ "$colorize" = 1 ] && __colorize "$cpu_temp" + if [ $multi_cpu = 1 ]; then + sep="|" + else + sep="" + multi_cpu=1 + fi + printf "%b%s%s%b%s" "$color" "$cpu_temp" "$unitsymbol" "$colend$colbgend" "$sep" + # Only one hwmonX should be in hwmon, pick the first in case of multiple + break + done +done + +[ "$newline" = 1 ] && printf "\n" || : diff --git a/screen/.screenrc b/screen/.screenrc index 7328e80..56e2dac 100755 --- a/screen/.screenrc +++ b/screen/.screenrc @@ -17,11 +17,12 @@ defscrollback 10000 # backtick id lifespan autorefresh cmd args... backtick 1 10 10 $HOME/.config/screen/bin/battery.sh --unit --symbols ascii --icon ascii --color screen backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --icon ascii --color screen +backtick 3 10 10 $HOME/.config/screen/bin/cputemp.sh --unit --color screen # Statusbar hardstatus on hardstatus alwayslastline -hardstatus string '%-Lw%?%E%{= ck}%:%{= mk}%? %n%f %t %{-}%+Lw%{= dd}%=%{b}%D %d %M %c%=%{K}[%{y}Avg: %l%{K}][%1`%{K}][%2`]' +hardstatus string '%-Lw%?%E%{= ck}%:%{= mk}%? %n%f %t %{-}%+Lw%{= dd}%=%{b}%D %d %M %c%=%{K}[%{y}Avg: %l%{K}][%3`%{K}][%2`][%1`]' # Window captions caption always