diff options
Diffstat (limited to '.config/luastatus-scripts-dwm/cpu-temperature.lua')
-rw-r--r-- | .config/luastatus-scripts-dwm/cpu-temperature.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.config/luastatus-scripts-dwm/cpu-temperature.lua b/.config/luastatus-scripts-dwm/cpu-temperature.lua new file mode 100644 index 0000000..38b25d0 --- /dev/null +++ b/.config/luastatus-scripts-dwm/cpu-temperature.lua @@ -0,0 +1,45 @@ +paths = {} +do + -- Replace "*" with "[^0]*" in the first glob if your zeroeth thermal sensor is virtual (and + -- thus useless): + local f = assert(io.popen([[ + #for file in /sys/class/thermal/thermal_zone*/temp + #do + # [ -e "$file" ] || break + # printf "%s\n" "$file" + #done +for dir in /sys/class/hwmon/* +do + [ -e "$dir" ] || break + IFS= read -r monitor_name < "$dir"/name + # You may have more than one hardware monitor enabled + # If so, disable ones that are not needed + case "$monitor_name" in + coretemp|fam15h_power|k10temp) + printf "%s\n" "$dir"/temp*_input + esac +done +]])) + for p in f:lines() do + table.insert(paths, p) + end + f:close() +end + +widget = { + plugin = 'timer', + opts = {period = 2}, + cb = function() + for _, p in ipairs(paths) do + local f = assert(io.open(p, 'r')) + local temp = f:read('*number') / 1000 + local icon = "" + if temp > 55 then + icon = "" + elseif temp > 80 then + icon = "" + end + return string.format('%s %.0f°C', icon, temp) + end + end, +} |