Rewrite cpu function to fix issues with speeds lowe than 1ghz
This commit is contained in:
parent
8d4057b1b8
commit
d1c3f30ba7
1 changed files with 33 additions and 45 deletions
78
neofetch
78
neofetch
|
@ -941,7 +941,29 @@ getwmtheme () {
|
|||
|
||||
getcpu () {
|
||||
case "$os" in
|
||||
"Linux")
|
||||
"Mac OS X")
|
||||
cpu="$(sysctl -n machdep.cpu.brand_string)"
|
||||
cores=$(sysctl -n hw.ncpu)
|
||||
;;
|
||||
|
||||
"Linux" | *"BSD" | "Windows")
|
||||
case "$distro" in
|
||||
"OpenBSD"* | "FreeBSD"*)
|
||||
# Get cpu name
|
||||
cpu="$(sysctl -n hw.model)"
|
||||
cpu=${cpu/[0-9]\.*}
|
||||
cpu=${cpu/ @*}
|
||||
|
||||
# Get cpu speed
|
||||
case "$distro" in
|
||||
"OpenBSD"*) speed=$(sysctl -n hw.cpuspeed) ;;
|
||||
"FreeBSD"*) speed=$(sysctl -n hw.clockrate) ;;
|
||||
esac
|
||||
speed=$((speed / 100))
|
||||
cores=$(sysctl -n hw.ncpu)
|
||||
;;
|
||||
|
||||
*)
|
||||
# Get cpu name
|
||||
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
|
||||
|
||||
|
@ -963,58 +985,24 @@ getcpu () {
|
|||
speed=$((speed / 100000))
|
||||
else
|
||||
speed=$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
|
||||
speed=$((speed / 100))
|
||||
fi
|
||||
speed=${speed:0:1}.${speed:1}
|
||||
|
||||
cpu="$cpu @ ${speed}GHz"
|
||||
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
cpu="$(sysctl -n machdep.cpu.brand_string)"
|
||||
cores=$(sysctl -n hw.ncpu)
|
||||
;;
|
||||
|
||||
*"BSD" | "Windows")
|
||||
case "$distro" in
|
||||
"OpenBSD"* | "FreeBSD"*)
|
||||
# Get cpu name
|
||||
cpu="$(sysctl -n hw.model)"
|
||||
cpu=${cpu/[0-9]\.*}
|
||||
cpu=${cpu/ @*}
|
||||
|
||||
# Get cpu speed
|
||||
case "$distro" in
|
||||
"OpenBSD"*) speed=$(sysctl -n hw.cpuspeed) ;;
|
||||
"FreeBSD"*) speed=$(sysctl -n hw.clockrate) ;;
|
||||
esac
|
||||
speed=$((speed / 100))
|
||||
cores=$(sysctl -n hw.ncpu)
|
||||
;;
|
||||
|
||||
"NetBSD"* | "Windows"*)
|
||||
# Get cpu name
|
||||
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
||||
cpu=${cpu/model name*: }
|
||||
cpu=${cpu/ @*}
|
||||
cpu=${cpu// }
|
||||
cpu=${cpu% }
|
||||
|
||||
# Get cpu speed
|
||||
speed="$(grep -F 'cpu MHz' /proc/cpuinfo)"
|
||||
speed=${speed/cpu MHz*: }
|
||||
speed=${speed/\.}
|
||||
|
||||
case "$distro" in
|
||||
"NetBSD"*) speed=$((speed / 10000)) ;;
|
||||
"Windows"*) speed=$((speed / 100000)) ;;
|
||||
*) speed=$((speed / 100)) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Fix for speeds under 1ghz
|
||||
if [ -z "${speed:1}" ]; then
|
||||
speed="0.${speed}"
|
||||
else
|
||||
speed=${speed:0:1}.${speed:1}
|
||||
fi
|
||||
|
||||
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
|
||||
;;
|
||||
esac
|
||||
|
||||
speed=${speed:0:1}.${speed:1}
|
||||
cpu="$cpu @ ${speed}GHz"
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue