From 0da7269a965f8894d4607b8574f7b36e963d467e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 28 Dec 2016 12:33:34 +1100 Subject: [PATCH] CPU: Add option to display output in fahrenheit --- config/config | 5 +++-- neofetch | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/config/config b/config/config index 2e33b74f..36ebe853 100644 --- a/config/config +++ b/config/config @@ -186,12 +186,13 @@ cpu_cores="logical" # Note the temperature is added to the regular CPU function. # # Default: 'off' -# Values: 'on', 'off' +# Values: 'C', 'F', 'off' # Flag: --cpu_temp # Supports: Linux # # 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' cpu_temp="off" diff --git a/neofetch b/neofetch index f56771d9..5aadb5f1 100755 --- a/neofetch +++ b/neofetch @@ -786,10 +786,15 @@ get_cpu() { fi # Get CPU temp. - if [[ "$cpu_temp" == "on" && -f "$temp_dir" ]]; then + if [[ "$cpu_temp" != "off" && -f "$temp_dir" ]]; then temp="$(< "$temp_dir")" 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 # Get CPU cores. @@ -851,17 +856,27 @@ get_cpu() { cores="$(sysctl -n hw.ncpu)" # Get CPU temp. - if [[ "$cpu_temp" == "on" ]]; then + if [[ "$cpu_temp" != "off" ]]; then case "$kernel_name" in "FreeBSD"* | "DragonFly"*) temp="$(sysctl -n dev.cpu.0.temperature)" - temp="[${temp/C/°C}]" + temp="${temp/C}" ;; "OpenBSD"* | "Bitrig"*) temp="$(sysctl -n hw.sensors.lm0.temp0)" - temp="[${temp/ degC/°C}]" + temp="${temp/ degC}" ;; 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 ;;