Linux: Add CPU temperature
This commit is contained in:
parent
9838c7cc5b
commit
3ef6aeea42
4 changed files with 45 additions and 6 deletions
|
@ -434,6 +434,9 @@ alias neofetch2="neofetch \
|
|||
--cpu_cores type Whether or not to display the number of CPU cores
|
||||
Takes: logical, physical, off
|
||||
Note: 'physical' doesn't work on BSD.
|
||||
--cpu_speed on/off Hide/Show cpu speed.
|
||||
--cpu_temp on/off Hide/Show cpu temperature.
|
||||
NOTE This only works on linux.
|
||||
--distro_shorthand on/off Shorten the output of distro (tiny, on, off)
|
||||
NOTE: This is only possible on Linux, macOS, and Solaris
|
||||
--kernel_shorthand on/off Shorten the output of kernel
|
||||
|
|
|
@ -106,6 +106,11 @@ cpu_shorthand="off"
|
|||
# --cpu_display bar, infobar, barinfo, off
|
||||
cpu_display="off"
|
||||
|
||||
# CPU Speed
|
||||
# Hide/Show CPU speed.
|
||||
# --cpu_speed on, off
|
||||
cpu_speed="on"
|
||||
|
||||
# CPU Cores
|
||||
# Display CPU cores in output
|
||||
# Logical: All virtual cores
|
||||
|
@ -114,6 +119,12 @@ cpu_display="off"
|
|||
# Note: 'physical' doesn't work on BSD.
|
||||
cpu_cores="logical"
|
||||
|
||||
# CPU Temperature
|
||||
# Hide/Show CPU temperature.
|
||||
# --cpu_temp on, off
|
||||
# Note: Only works on Linux.
|
||||
cpu_temp="on"
|
||||
|
||||
|
||||
# GPU
|
||||
|
||||
|
|
29
neofetch
29
neofetch
|
@ -686,10 +686,11 @@ getcpu() {
|
|||
"Linux" | "Windows")
|
||||
# Get cpu name
|
||||
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
|
||||
cpu_dir="/sys/devices/system/cpu/cpu0/cpufreq"
|
||||
speed_dir="/sys/devices/system/cpu/cpu0/cpufreq"
|
||||
temp_dir="/sys/class/hwmon/hwmon0/temp1_input"
|
||||
|
||||
# Get cpu speed
|
||||
if [ -d "$cpu_dir" ]; then
|
||||
if [ -d "$speed_dir" ]; then
|
||||
case "$speed_type" in
|
||||
current) speed_type="scaling_cur_freq" ;;
|
||||
min) speed_type="scaling_min_freq" ;;
|
||||
|
@ -701,8 +702,8 @@ getcpu() {
|
|||
esac
|
||||
|
||||
# Fallback to cpuinfo_max_freq if $speed_type fails
|
||||
read -t 1 -r speed < "${cpu_dir}/${speed_type}" || \
|
||||
read -t 1 -r speed < "${cpu_dir}/cpuinfo_max_freq"
|
||||
read -t 1 -r speed < "${speed_dir}/${speed_type}" || \
|
||||
read -t 1 -r speed < "${speed_dir}/cpuinfo_max_freq"
|
||||
|
||||
speed="$((speed / 100000))"
|
||||
else
|
||||
|
@ -710,6 +711,13 @@ getcpu() {
|
|||
speed="$((speed / 100))"
|
||||
fi
|
||||
|
||||
# Get cpu temp
|
||||
if [ "$cpu_temp" == "on" ] && [ -f "$temp_dir" ]; then
|
||||
temp="$(< "$temp_dir")"
|
||||
temp="$((temp * 100 / 10000))"
|
||||
temp="[${temp/${temp: -1}}.${temp: -1}°C]"
|
||||
fi
|
||||
|
||||
# Show/hide hyperthreaded cores
|
||||
case "$cpu_cores" in
|
||||
"logical" | "on") cores="$(grep -c ^processor /proc/cpuinfo)" ;;
|
||||
|
@ -723,7 +731,7 @@ getcpu() {
|
|||
speed="${speed:0:1}.${speed:1}"
|
||||
fi
|
||||
|
||||
cpu="$cpu @ ${speed}GHz"
|
||||
cpu="$cpu @ ${speed}GHz $temp"
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
|
@ -914,6 +922,10 @@ getcpu() {
|
|||
[ "$cpu_cores" != "off" ] && [ "$cores" ] && \
|
||||
cpu="${cpu/@/(${cores}) @}"
|
||||
|
||||
# Remove speed from output
|
||||
[ "$cpu_speed" == "off" ] && \
|
||||
cpu="${cpu/@ *GHz}"
|
||||
|
||||
# Make the output of cpu shorter
|
||||
case "$cpu_shorthand" in
|
||||
"name") cpu="${cpu/@*}" ;;
|
||||
|
@ -2991,7 +3003,10 @@ usage() { cat << EOF
|
|||
Possible values: name, speed, tiny, on, off
|
||||
--cpu_cores type Whether or not to display the number of CPU cores
|
||||
Takes: logical, physical, off
|
||||
Note: 'physical' doesn't work on BSD.
|
||||
NOTE: 'physical' doesn't work on BSD.
|
||||
--cpu_speed on/off Hide/Show cpu speed.
|
||||
--cpu_temp on/off Hide/Show cpu temperature.
|
||||
NOTE This only works on linux.
|
||||
--distro_shorthand on/off Shorten the output of distro (tiny, on, off)
|
||||
NOTE: This is only possible on Linux, macOS, and Solaris
|
||||
--kernel_shorthand on/off Shorten the output of kernel
|
||||
|
@ -3119,6 +3134,8 @@ getargs() {
|
|||
# Info
|
||||
--os_arch) os_arch="$2" ;;
|
||||
--cpu_cores) cpu_cores="$2" ;;
|
||||
--cpu_speed) cpu_speed="$2" ;;
|
||||
--cpu_temp) cpu_temp="$2" ;;
|
||||
--speed_type) speed_type="$2" ;;
|
||||
--distro_shorthand) distro_shorthand="$2" ;;
|
||||
--kernel_shorthand) kernel_shorthand="$2" ;;
|
||||
|
|
|
@ -40,6 +40,14 @@ Whether or not to display the number of CPU cores
|
|||
.br
|
||||
Note: 'physical' doesn't work on BSD.
|
||||
.TP
|
||||
.B \--cpu_speed 'on/off'
|
||||
Hide/Show cpu speed.
|
||||
.TP
|
||||
.B \--cpu_temp 'on/off'
|
||||
Hide/Show cpu temperature.
|
||||
.br
|
||||
NOTE This only works on linux.
|
||||
.TP
|
||||
.B \--distro_shorthand 'on/off'
|
||||
Shorten the output of distro (tiny, on, off)
|
||||
.br
|
||||
|
|
Loading…
Reference in a new issue