Merge pull request #149 from iandrewt/cpu_cores

added cpu cores so the usage bar doesn't go crazy above 100%
This commit is contained in:
Dylan Araps 2016-03-15 19:13:43 +11:00
commit aa7c735f00
4 changed files with 26 additions and 4 deletions

View file

@ -293,6 +293,7 @@ alias fetch2="fetch \
NOTE: This only support Linux with cpufreq. NOTE: This only support Linux with cpufreq.
--cpu_shorthand type Shorten the output of CPU --cpu_shorthand type Shorten the output of CPU
Possible values: name, speed, tiny, on, off Possible values: name, speed, tiny, on, off
--cpu_cores on/off Whether or not to display the number of CPU cores
--kernel_shorthand on/off Shorten the output of kernel --kernel_shorthand on/off Shorten the output of kernel
--uptime_shorthand on/off Shorten the output of uptime (tiny, on, off) --uptime_shorthand on/off Shorten the output of uptime (tiny, on, off)
--gpu_shorthand on/off Shorten the output of GPU (tiny, on, off) --gpu_shorthand on/off Shorten the output of GPU (tiny, on, off)

View file

@ -103,6 +103,11 @@ speed_type="max"
cpu_shorthand="off" cpu_shorthand="off"
cpu_display="off" cpu_display="off"
# CPU Cores
# Display CPU cores in output
# --cpu_cores on/off
cpu_cores="on"
# GPU # GPU

View file

@ -125,6 +125,10 @@ speed_type="max"
cpu_shorthand="off" cpu_shorthand="off"
cpu_display="off" cpu_display="off"
# CPU Cores
# Display CPU cores in output
# --cpu_cores on/off
cpu_cores="on"
# GPU # GPU
@ -849,11 +853,13 @@ getcpu () {
speed=${speed:0:1}.${speed:1} speed=${speed:0:1}.${speed:1}
cpu="$cpu @ ${speed}GHz" cpu="$cpu @ ${speed}GHz"
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
;; ;;
"Mac OS X") "Mac OS X")
cpu="$(sysctl -n machdep.cpu.brand_string)" cpu="$(sysctl -n machdep.cpu.brand_string)"
cpu=${cpu/ } cpu=${cpu/ }
cores=$(sysctl -n hw.ncpu)
;; ;;
*"BSD" | "Windows") *"BSD" | "Windows")
@ -871,6 +877,7 @@ getcpu () {
"FreeBSD"*) speed=$(sysctl -n hw.clockrate) ;; "FreeBSD"*) speed=$(sysctl -n hw.clockrate) ;;
esac esac
speed=$((speed / 100)) speed=$((speed / 100))
cores=$(sysctl -n hw.ncpu)
;; ;;
"NetBSD"* | "Windows"*) "NetBSD"* | "Windows"*)
@ -888,8 +895,9 @@ getcpu () {
case "$distro" in case "$distro" in
"NetBSD"*) speed=$((speed / 10000)) ;; "NetBSD"*) speed=$((speed / 10000)) ;;
"WindowS"*) speed=$((speed / 100000)) ;; "Windows"*) speed=$((speed / 100000)) ;;
esac esac
cores=$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)
;; ;;
esac esac
@ -914,6 +922,10 @@ getcpu () {
cpu=${cpu// Eight-Core} cpu=${cpu// Eight-Core}
cpu=${cpu// with Radeon HD Graphics} cpu=${cpu// with Radeon HD Graphics}
# Add cpu cores to output
[ "$cpu_cores" == "on" ] && \
cpu=${cpu/@/\(${cores}\) @}
# Make the output of cpu shorter # Make the output of cpu shorter
case "$cpu_shorthand" in case "$cpu_shorthand" in
"name") "name")
@ -944,9 +956,9 @@ getcpu () {
case "$cpu_display" in case "$cpu_display" in
"info") prin "${subtitle} Usage: ${cpu_usage}" ;; "info") prin "${subtitle} Usage: ${cpu_usage}" ;;
"bar") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" 100)" ;; "bar") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;;
"infobar") prin "${subtitle} Usage: ${cpu_usage} $(bar "${cpu_usage/'%'}" 100)" ;; "infobar") prin "${subtitle} Usage: ${cpu_usage} $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} )))" ;;
"barinfo") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" 100) ${cpu_usage}" ;; "barinfo") prin "${subtitle} Usage: $(bar "${cpu_usage/'%'}" $(( 100 * ${cores} ))) ${cpu_usage}" ;;
esac esac
unset cpu unset cpu
} }
@ -2479,6 +2491,7 @@ usage () { cat << EOF
NOTE: This only support Linux with cpufreq. NOTE: This only support Linux with cpufreq.
--cpu_shorthand type Shorten the output of CPU --cpu_shorthand type Shorten the output of CPU
Possible values: name, speed, tiny, on, off Possible values: name, speed, tiny, on, off
--cpu_cores on/off Whether or not to display the number of CPU cores
--kernel_shorthand on/off Shorten the output of kernel --kernel_shorthand on/off Shorten the output of kernel
--uptime_shorthand on/off Shorten the output of uptime (tiny, on, off) --uptime_shorthand on/off Shorten the output of uptime (tiny, on, off)
--gpu_shorthand on/off Shorten the output of GPU (tiny, on, off) --gpu_shorthand on/off Shorten the output of GPU (tiny, on, off)

View file

@ -41,6 +41,9 @@ Shorten the output of CPU
.br .br
Possible values: name, speed, tiny, on, off Possible values: name, speed, tiny, on, off
.TP .TP
.B \--cpu_cores 'on/off'
Whether or not to display the number of CPU cores
.TP
.B \--kernel_shorthand 'on/off' .B \--kernel_shorthand 'on/off'
Shorten the output of kernel Shorten the output of kernel
.TP .TP