From 46672786ab4192cd8c2fdfc218666baefed210fd Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 25 Nov 2022 14:59:49 -0500 Subject: [PATCH] Add temperature to waybar in FreeBSD. --- ansible/roles/sway/files/style.css | 1 + ansible/roles/sway/files/waybar_config.json | 7 ++- .../waybar_temperature_freebsd.bash | 46 +++++++++++++++++++ ansible/roles/sway/tasks/freebsd.yaml | 2 + 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/sway/files/waybar_scripts/waybar_temperature_freebsd.bash diff --git a/ansible/roles/sway/files/style.css b/ansible/roles/sway/files/style.css index 7acad3b..fd0f687 100644 --- a/ansible/roles/sway/files/style.css +++ b/ansible/roles/sway/files/style.css @@ -59,6 +59,7 @@ #custom-battery, #custom-clock, #custom-sound, +#custom-temperature, #idle_inhibitor, #memory, #mode, diff --git a/ansible/roles/sway/files/waybar_config.json b/ansible/roles/sway/files/waybar_config.json index 564cf37..d6949c3 100644 --- a/ansible/roles/sway/files/waybar_config.json +++ b/ansible/roles/sway/files/waybar_config.json @@ -1,7 +1,7 @@ { // "height": 10, // Waybar height (to be removed for auto height) "modules-left": ["sway/workspaces", "sway/mode"], - "modules-right": ["custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"], + "modules-right": ["custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"], "sway/workspaces": { "disable-scroll": true }, @@ -38,5 +38,10 @@ "exec": "waybar_custom_sound", "return-type": "json", "restart-interval": 30 + }, + "custom/temperature": { + "exec": "waybar_custom_temperature", + "return-type": "json", + "restart-interval": 30 } } diff --git a/ansible/roles/sway/files/waybar_scripts/waybar_temperature_freebsd.bash b/ansible/roles/sway/files/waybar_scripts/waybar_temperature_freebsd.bash new file mode 100644 index 0000000..25c9310 --- /dev/null +++ b/ansible/roles/sway/files/waybar_scripts/waybar_temperature_freebsd.bash @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# Read temperature status in FreeBSD +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +SLEEP_INTERVAL=${SLEEP_INTERVAL:-30} + +while true; do + current_cpu_temps=$(sysctl 'dev.cpu' | grep -E 'dev\.cpu\.[0-9]+\.temperature') + sum_temperature=0 + num_temperature=0 + max_temperature=0 + while read temp; do + numeric_temp=$(echo "$temp" | cut -d ':' -f 2 | grep -oE '[0-9]+(\.[0-9]+)?') + sum_temperature=$(bc -s <<<"$sum_temperature + $numeric_temp") + num_temperature=$((num_temperature + 1)) + max_temperature=$(bc <b) + { + return(a) + }else{ + return(b) + } +} +max($max_temperature,$numeric_temp) +EOF +) + done<<<"$current_cpu_temps" + avg_temperature=$(bc -s <<<"$sum_temperature / $num_temperature") + tooltip="$current_cpu_temps" + class="" + icon="🌡" + + jq --unbuffered --compact-output <