CPU: Add option to display output in fahrenheit

This commit is contained in:
Dylan Araps 2016-12-28 12:33:34 +11:00
parent b5757417d5
commit 0da7269a96
2 changed files with 23 additions and 7 deletions

View File

@ -186,12 +186,13 @@ cpu_cores="logical"
# Note the temperature is added to the regular CPU function. # Note the temperature is added to the regular CPU function.
# #
# Default: 'off' # Default: 'off'
# Values: 'on', 'off' # Values: 'C', 'F', 'off'
# Flag: --cpu_temp # Flag: --cpu_temp
# Supports: Linux # Supports: Linux
# #
# Example: # Example:
# on: 'Intel i7-6500U (4) @ 3.1GHz [27.2°C]' # C: 'Intel i7-6500U (4) @ 3.1GHz [27.2°C]'
# F: 'Intel i7-6500U (4) @ 3.1GHz [82.0°C]'
# off: 'Intel i7-6500U (4) @ 3.1GHz' # off: 'Intel i7-6500U (4) @ 3.1GHz'
cpu_temp="off" cpu_temp="off"

View File

@ -786,10 +786,15 @@ get_cpu() {
fi fi
# Get CPU temp. # Get CPU temp.
if [[ "$cpu_temp" == "on" && -f "$temp_dir" ]]; then if [[ "$cpu_temp" != "off" && -f "$temp_dir" ]]; then
temp="$(< "$temp_dir")" temp="$(< "$temp_dir")"
temp="$((temp * 100 / 10000))" temp="$((temp * 100 / 10000))"
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
# Convert to fahrenheit if enabled.
[[ "$cpu_temp" == "F" ]] && temp="$((temp * 90 / 50 + 320))"
# Format the output.
temp="[${temp/${temp: -1}}.${temp: -1}°${cpu_temp:-C}]"
fi fi
# Get CPU cores. # Get CPU cores.
@ -851,17 +856,27 @@ get_cpu() {
cores="$(sysctl -n hw.ncpu)" cores="$(sysctl -n hw.ncpu)"
# Get CPU temp. # Get CPU temp.
if [[ "$cpu_temp" == "on" ]]; then if [[ "$cpu_temp" != "off" ]]; then
case "$kernel_name" in case "$kernel_name" in
"FreeBSD"* | "DragonFly"*) "FreeBSD"* | "DragonFly"*)
temp="$(sysctl -n dev.cpu.0.temperature)" temp="$(sysctl -n dev.cpu.0.temperature)"
temp="[${temp/C/°C}]" temp="${temp/C}"
;; ;;
"OpenBSD"* | "Bitrig"*) "OpenBSD"* | "Bitrig"*)
temp="$(sysctl -n hw.sensors.lm0.temp0)" temp="$(sysctl -n hw.sensors.lm0.temp0)"
temp="[${temp/ degC/°C}]" temp="${temp/ degC}"
;; ;;
esac esac
# Convert to fahrenheit if enabled.
if [[ "$cpu_temp" == "F" ]]; then
temp="${temp//.}"
temp="$((temp * 90 / 50 + 320))"
temp="[${temp/${temp: -1}}.${temp: -1}°F]"
else
temp="[${temp}°C]"
fi
fi fi
;; ;;