From a3b14a9966f813b503cec0a4dc5fcfb0c51dac58 Mon Sep 17 00:00:00 2001 From: Lincoln Wallace Date: Sat, 19 Oct 2024 08:23:41 -0300 Subject: [PATCH 1/4] add: Generic system temperature support * Complements #149 * Use lm-sensors package to read temperature * Detect raspberry Pi and keep using vcgencmd in case. Signed-off-by: Lincoln Wallace --- README.md | 2 +- scripts/dracula.sh | 4 ++-- scripts/{rpi_temp.sh => sys_temp.sh} | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) rename scripts/{rpi_temp.sh => sys_temp.sh} (53%) diff --git a/README.md b/README.md index 8ee1a13b..e619119e 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul set -g @dracula-show-battery-status true ``` - If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature -- System temperature on Raspberry PI +- System temperature on Raspberry PI and on regular computers - Info if the Panes are synchronized - Spotify playback (needs the tool spotify-tui installed). max-len can be configured. - Music Player Daemon status (needs the tool mpc installed) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 14363b27..794ee689 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -298,9 +298,9 @@ main() continue fi - if [ $plugin = "rpi-temp" ]; then + if [ $plugin = "sys-temp" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-rpi-temp-colors" "green dark_gray") - script="#($current_dir/rpi_temp.sh)" + script="#($current_dir/sys_temp.sh)" fi if $show_powerline; then diff --git a/scripts/rpi_temp.sh b/scripts/sys_temp.sh similarity index 53% rename from scripts/rpi_temp.sh rename to scripts/sys_temp.sh index 25898c2e..a2f6ace2 100755 --- a/scripts/rpi_temp.sh +++ b/scripts/sys_temp.sh @@ -3,7 +3,13 @@ export LC_ALL=en_US.UTF-8 get_temp() { - echo "$(vcgencmd measure_temp | sed 's/temp=//')" + if [[ -d "/proc/device-tree/" && -f "/proc/device-tree/model" && $(grep -i 'Raspberry' /proc/device-tree/model) ]]; then + # It's a Raspberry pi + echo "$(vcgencmd measure_temp | sed 's/temp=//')" + else + # It's a Regular pc + echo "$(sensors | grep 'Tctl' | awk '{print substr($2, 2)}')" + fi } main() { From 780991acb16ca0de7f904f3a7d6f51de9b33552b Mon Sep 17 00:00:00 2001 From: Lincoln Wallace Date: Sat, 19 Oct 2024 08:37:05 -0300 Subject: [PATCH 2/4] fix: improve checking Signed-off-by: Lincoln Wallace --- scripts/sys_temp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sys_temp.sh b/scripts/sys_temp.sh index a2f6ace2..2b382911 100755 --- a/scripts/sys_temp.sh +++ b/scripts/sys_temp.sh @@ -3,7 +3,7 @@ export LC_ALL=en_US.UTF-8 get_temp() { - if [[ -d "/proc/device-tree/" && -f "/proc/device-tree/model" && $(grep -i 'Raspberry' /proc/device-tree/model) ]]; then + if grep -q "Raspberry" /proc/device-tree/model; then # It's a Raspberry pi echo "$(vcgencmd measure_temp | sed 's/temp=//')" else From 59b6c981128c51cfd7a2a5222483f51afba2ed26 Mon Sep 17 00:00:00 2001 From: Lincoln Wallace Date: Sat, 19 Oct 2024 08:39:34 -0300 Subject: [PATCH 3/4] fix: suppress error msg Signed-off-by: Lincoln Wallace --- scripts/sys_temp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sys_temp.sh b/scripts/sys_temp.sh index 2b382911..e6d19a07 100755 --- a/scripts/sys_temp.sh +++ b/scripts/sys_temp.sh @@ -3,7 +3,7 @@ export LC_ALL=en_US.UTF-8 get_temp() { - if grep -q "Raspberry" /proc/device-tree/model; then + if grep -q "Raspberry" /proc/device-tree/model 2>/dev/null; then # It's a Raspberry pi echo "$(vcgencmd measure_temp | sed 's/temp=//')" else From 8efdc955df0d6dabca42d65c9bd5fe69a2651379 Mon Sep 17 00:00:00 2001 From: Lincoln Wallace Date: Mon, 21 Oct 2024 12:19:09 -0300 Subject: [PATCH 4/4] refact: addressing reviews Signed-off-by: Lincoln Wallace --- README.md | 2 +- scripts/dracula.sh | 2 +- scripts/sys_temp.sh | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e619119e..8a0e8122 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul set -g @dracula-show-battery-status true ``` - If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature -- System temperature on Raspberry PI and on regular computers +- Read system temperature - Info if the Panes are synchronized - Spotify playback (needs the tool spotify-tui installed). max-len can be configured. - Music Player Daemon status (needs the tool mpc installed) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 794ee689..bcc3483d 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -299,7 +299,7 @@ main() fi if [ $plugin = "sys-temp" ]; then - IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-rpi-temp-colors" "green dark_gray") + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-sys-temp-colors" "green dark_gray") script="#($current_dir/sys_temp.sh)" fi diff --git a/scripts/sys_temp.sh b/scripts/sys_temp.sh index e6d19a07..403c782f 100755 --- a/scripts/sys_temp.sh +++ b/scripts/sys_temp.sh @@ -7,7 +7,6 @@ get_temp() { # It's a Raspberry pi echo "$(vcgencmd measure_temp | sed 's/temp=//')" else - # It's a Regular pc echo "$(sensors | grep 'Tctl' | awk '{print substr($2, 2)}')" fi }