Merge remote-tracking branch 'origin/temp_unit'

This commit is contained in:
Casper da Costa-Luis 2021-02-12 18:20:35 +00:00
commit 99e7ef7fe8
No known key found for this signature in database
GPG key ID: D88C553DBD362CDE
3 changed files with 10 additions and 3 deletions

View file

@ -135,7 +135,7 @@ Here are all available options with their default values:
@ram_(low_icon,high_bg_color,etc...) # same defaults as above
@cpu_temp_format "%2.0f" # printf format to use to display temperature
@cpu_temp_units "C" # supports C & F
@cpu_temp_unit "C" # supports C & F
@cpu_temp_medium_thresh "80" # medium temperature threshold
@cpu_temp_high_thresh "90" # high temperature threshold

View file

@ -11,7 +11,7 @@ print_cpu_temp() {
cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format")
cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit")
if command_exists "sensors"; then
([ "$cpu_temp_unit" == F ] && sensors -f || sensors) | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[^0-9.]", "", $3); sum+=$3; n+=1} END {printf(format, sum/n)}'
([ "$cpu_temp_unit" == F ] && sensors -f || sensors) | sed -e 's/^Tccd/Core /' | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[^0-9.]", "", $3); sum+=$3; n+=1} END {printf(format, sum/n)}'
fi
}

View file

@ -5,9 +5,11 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
gpu_temp_format="%2.0f"
gpu_temp_unit="C"
print_gpu_temp() {
gpu_temp_format=$(get_tmux_option "@gpu_temp_format" "$gpu_temp_format")
gpu_temp_unit=$(get_tmux_option "@gpu_temp_unit" "$gpu_temp_unit")
if command_exists "nvidia-smi"; then
loads=$(cached_eval nvidia-smi)
@ -17,7 +19,12 @@ print_gpu_temp() {
echo "No GPU"
return
fi
echo "$loads" | sed -nr 's/.*\s([0-9]+)C.*/\1/p' | awk -v format="${gpu_temp_format}C" '{sum+=$1; n+=1} END {printf format, sum/n}'
tempC=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)C.*/\1/p' | awk '{sum+=$1; n+=1} END {printf "%5.3f", sum/n}')
if [ $gpu_temp_unit == "C" ]; then
echo "$tempC" | awk -v format="${gpu_temp_format}C" '{sum+=$1} END {printf format, sum}'
else
echo "$tempC" | awk -v format="${gpu_temp_format}F" '{sum+=$1} END {printf format, sum*9/5+32}'
fi
}
main() {