Created
December 19, 2020 12:16
-
-
Save korc/fd1557efa352fc8265917a3a219cce3f to your computer and use it in GitHub Desktop.
i3 status bar (cpu) temperature display enhancement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# colorize hardware temperatures for i3status (more red as temp gets closer to crit) | |
# (shell internal commands only) | |
## this script expects i3status to give output in the format of "i3bar", | |
## and having a placeholder with string "TEMPERATURE" | |
## .config/i3status/config should contain something like this: | |
# general { | |
# output_format = "i3bar" | |
# } | |
# order += "cpu_temperature 0" | |
# cpu_temperature 0 { | |
# format = "TEMPERATURE" | |
# } | |
fix_name() { | |
case "$1" in | |
pch_skylake) echo "MB" ;; | |
acpitz) echo "ACPI" ;; | |
x86_pkg_temp) echo "x86" ;; | |
asus) echo "ASUS" ;; | |
cpu_fan) echo "CFN" ;; | |
iwlwifi_*) echo "WiFi${1#iwlwifi_}" ;; | |
"Package id "[0-9]) echo "CPU${1#Package id }" ;; | |
"Core "[0-9]) echo "C${1#Core }" ;; | |
*) echo "$1" ;; | |
esac | |
} | |
read_hwmon() { | |
local out="" | |
for temp_file in /sys/class/hwmon/hwmon*/temp*_input; do | |
read temp <"$temp_file" || continue | |
color="" | |
test ! -e "${temp_file%_input}_crit" || { | |
read crit < "${temp_file%_input}_crit" | |
perc="$(( ($temp-20000)*255/($crit-20000)))" | |
color="$(printf "#%02x%02x%02x" $perc $((255-$perc)) 0)" | |
} | |
test -e "${temp_file%_input}_label" && read name <"${temp_file%_input}_label" || read name <"${temp_file%/*}/name" | |
out="${out:+$out,}{\"full_text\":\"$(fix_name "$name") ${temp%???}°C\"${color:+,\"color\":\"$color\"}}" | |
for fan_input in "${temp_file%/*}"/fan*_input; do | |
test -e "$fan" || continue | |
read fan <"$fan_input" || continue | |
read name <"${fan_input%_input}_label" | |
out="${out:+$out,}{\"full_text\":\"$(fix_name "$name") ${fan}RPM\"}" | |
done | |
done | |
echo "$out" | |
} | |
fix_i3status() { | |
local line="$1" | |
local before="${line%%TEMPERATURE*}" after="${line##*TEMPERATURE}" | |
before="${before%\{*}" | |
after="${after#*\}}" | |
case "${line%%TEMPERATURE*}" in | |
"$line") echo "$line" ;; | |
*) echo "${before}$(read_hwmon)${after}" ;; | |
esac | |
} | |
i3status | while read line; do | |
fix_i3status "$line" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment