-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathcpu_temp.sh
executable file
·37 lines (32 loc) · 1004 Bytes
/
cpu_temp.sh
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
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
cpu_temp_format="%2.0f"
cpu_temp_unit="C"
print_cpu_temp() {
cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format")
cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit")
if command_exists "sensors"; then
local val
if [[ "$cpu_temp_unit" == F ]]; then
val="$(sensors -f)"
else
val="$(sensors)"
fi
val=$(echo "$val" | sed -e 's/^Tccd/Core /')
if [[ $val =~ Core ]]; then
echo "$val" | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[^0-9.]", "", $3); sum+=$3; n+=1} END {printf(format, sum/n)}'
elif [[ $val =~ Tctl ]]; then
echo "$val" | sed -n 's/Tctl:\s*+//p' | tr -d " "
elif [[ $val =~ Tdie ]]; then
echo "$val" | sed -n 's/Tdie:\s*+//p' | tr -d " "
else
echo "NA"
fi
fi
}
main() {
print_cpu_temp
}
main