summaryrefslogtreecommitdiff
path: root/polybar/scripts/temp-status.sh
blob: d1f7665a443b328f63ba68ae4ae8b59a753c553b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -euo pipefail

temp=""

if command -v sensors >/dev/null 2>&1; then
  temp="$(
    sensors 2>/dev/null |
      awk '
        /Package id 0:/ { gsub(/[^0-9.-]/, "", $4); print int($4); exit }
        /Tctl:/ { gsub(/[^0-9.-]/, "", $2); print int($2); exit }
        /temp1:/ && $2 ~ /^\+/ { gsub(/[^0-9.-]/, "", $2); print int($2); exit }
      '
  )"
fi

if [ -z "$temp" ]; then
  for zone in /sys/class/thermal/thermal_zone*/temp; do
    [ -r "$zone" ] || continue
    value="$(cat "$zone")"
    if [ "$value" -gt 0 ] 2>/dev/null; then
      temp=$((value / 1000))
      break
    fi
  done
fi

if [ -z "$temp" ]; then
  echo "n/a"
elif [ "$temp" -ge 80 ]; then
  echo "%{F#cc241d}${temp}C%{F-}"
elif [ "$temp" -ge 65 ]; then
  echo "%{F#d79921}${temp}C%{F-}"
else
  echo "${temp}C"
fi