summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/cpuinfo
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2023-03-14 14:10:25 +0000
committer0scar <qgt268@alumni.ku.dk>2023-03-14 14:10:25 +0000
commit04e3e300bd0c6c01ba5e8a3a3f0d40ea29c95945 (patch)
tree32685f3fa8a42441772159ce5d7ef1a1163956c1 /.local/bin/statusbar/cpuinfo
parent4f266ca205ccfd685ac4c1ec85236d7d41691c61 (diff)
Update cpuinfo script
* Remove colors * Dont print anything if load < 1 * Conform to posix sh
Diffstat (limited to '.local/bin/statusbar/cpuinfo')
-rwxr-xr-x.local/bin/statusbar/cpuinfo18
1 files changed, 7 insertions, 11 deletions
diff --git a/.local/bin/statusbar/cpuinfo b/.local/bin/statusbar/cpuinfo
index 05ab3de..78920a5 100755
--- a/.local/bin/statusbar/cpuinfo
+++ b/.local/bin/statusbar/cpuinfo
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
set -e
ARG=${1:-$BLOCK_BUTTON}
@@ -20,16 +20,12 @@ case $ARG in
;;
esac
-# Thermals
-# "Never cat something into awk", yeah, but it won't function properly if it
-# encounters a missing `/temp`-file.
-TEMP="$(cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null)"
-TEMP="$(echo "${TEMP}" | awk '{s+=$1}END{printf "%.1f", s / (1000*NR)}' )"
-# Color red if temp > 45
-TEMP=`(( $(echo "$TEMP > 45" | bc -l) )) && echo -en "\x0c${TEMP}\x0b" || echo -en "$TEMP"`
+LOAD_1m=$(sed -E 's/^([^ ]+).*/\1/' /proc/loadavg | tr -d '\n')
-# Load
-LOAD=$(sed -Ee 's/^([0-9]+\.[0-9]+) .*/\1/g' /proc/loadavg | tr -d '\n')
+# Silence is golden
+[ "$(echo "${LOAD_1m} < 1" | bc -l)" -eq 1 ] && exit 0
+# Thermals
+TEMP="$(awk '{s+=$1}END{printf "%.1f", s / (1000*NR)}' /sys/class/thermal/thermal_zone*/temp)"
-echo -en "[${LOAD} \x0f\x0b ${TEMP}°]"
+printf "[%s  %s°]" "${LOAD_1m}" "${TEMP}"