Repository navigation
Expand file tree
/
Copy pathbash-function-temperature
More file actions
90 lines (68 loc) · 1.8 KB
/
Copy pathbash-function-temperature
File metadata and controls
90 lines (68 loc) · 1.8 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# loaded by "${HOME}"/.local/bin/bash-functions
# temperature ──────────────────────────────────────────────────────────────────
temperature () {
local count_acpitz
local label_cpu
local degrees_cpu
local list_lines
local length_label_longest
local directory_zone
local label
local degrees
local width_label
# output starts one line below the command
echo
if [[ -d /sys/class/thermal ]]
then
count_acpitz=0
label_cpu=""
degrees_cpu=""
list_lines=()
length_label_longest=0
for directory_zone in /sys/class/thermal/thermal_zone*
do
label=$(cat "${directory_zone}"/type)
if [ "${label}" = "acpitz" ]
then
count_acpitz=$(( count_acpitz + 1 ))
label="System ${count_acpitz}"
elif [[ "${label}" = pch_* ]]
then
label="Chipset"
elif [[ "${label}" = iwlwifi_* ]]
then
label="WiFi"
elif [ "${label}" = "x86_pkg_temp" ]
then
label="CPU"
else
label="${label//_/ }"
fi
degrees=$(cat "${directory_zone}"/temp)
degrees=$(( degrees / 1000 ))
if [ "${#label}" -gt "${length_label_longest}" ]
then
length_label_longest="${#label}"
fi
if [ "${label}" = "CPU" ]
then
label_cpu="${label}"
degrees_cpu="${degrees}"
else
list_lines+=("${label}|${degrees}")
fi
done
width_label=$(( length_label_longest + 4 ))
if [ -n "${label_cpu}" ]
then
printf "%-${width_label}s%s°C\n" "${label_cpu}:" "${degrees_cpu}"
fi
printf '%s\n' "${list_lines[@]}" | sort |
while IFS='|' read -r label degrees
do
printf "%-${width_label}s%s°C\n" "${label}:" "${degrees}"
done
unset count_acpitz label_cpu degrees_cpu list_lines length_label_longest width_label
fi
}