From d65aa4bc6b8febccb1a3e67ad12f09d9e62f6d5a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 19:40:54 +1000 Subject: [PATCH 01/15] Fix cpu usage --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 946f9a95..d1111355 100755 --- a/neofetch +++ b/neofetch @@ -1149,13 +1149,13 @@ getcpu () { if [ "$cpu_display" != "off" ]; then cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" - cpu_usage="${cpu_usage/\.*}%" + cpu_usage=$((${cpu_usage/\.*} / cores)) case "$cpu_display" in - "info") prin "$subtitle Usage" "$cpu_usage" ;; - "bar") prin "$subtitle Usage" "$(bar "${cpu_usage/'%'}" $(( 100 * cores )))" ;; - "infobar") prin "$subtitle Usage" "${cpu_usage} $(bar "${cpu_usage/'%'}" $(( 100 * cores )))" ;; - "barinfo") prin "$subtitle Usage" "$(bar "${cpu_usage/'%'}" $(( 100 * cores ))) $cpu_usage" ;; + "info") prin "$subtitle Usage" "${cpu_usage}%" ;; + "bar") prin "$subtitle Usage" "$(bar "$cpu_usage" 100)" ;; + "infobar") prin "$subtitle Usage" "${cpu_usage}% $(bar $cpu_usage 100)" ;; + "barinfo") prin "$subtitle Usage" "$(bar $cpu_usage 100) ${cpu_usage}%" ;; esac fi [ "$stdout_mode" != "on" ] && unset cpu From c69a8f241803136eca1dd4d94f1704f69ca1aad3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:22:38 +1000 Subject: [PATCH 02/15] Move CPU Usage to its own function --- README.md | 7 ++--- config/config | 11 +++++--- neofetch | 71 ++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index bb14c43a..6e507f0f 100644 --- a/README.md +++ b/README.md @@ -389,8 +389,6 @@ alias fetch2="fetch \ --underline_char char Character to use when underlining title --line_wrap on/off Enable/Disable line wrapping --bold on/off Enable/Disable bold text - --prompt_height num Set this to your prompt height to fix issues with - the text going off screen at the top Color Blocks: @@ -407,9 +405,8 @@ alias fetch2="fetch \ --progress_length num Length in spaces to make the progress bars. --progress_colors num num Colors to make the progress bar. Set in this order: elapsed, total - --cpu_display mode1 mode2 Which shorthand to use and how CPU usage should be printed - mode1 takes: name, speed, tiny, on, off - mode2 takes: info, bar, infobar, barinfo + --cpu_display mode Which way should the cpu progress bar be added + Takes bar, infobar, barinfo --memory_display mode Which way should the memory progress bar be added Takes bar, infobar, barinfo --battery_display mode Which way should the battery progress bar be added diff --git a/config/config b/config/config index 19dd34bb..533b8e3d 100644 --- a/config/config +++ b/config/config @@ -99,10 +99,14 @@ shell_version="off" # scaling_current, scaling_min, scaling_max speed_type="max" -# CPU Display -# Set shorthand setting and progress bar setting -# --cpu_display (name, speed, tiny, on, off) (bar, infobar, barinfo, off) +# CPU Shorthand +# Set shorthand setting +# --cpu_shorthand name, speed, tiny, on, off cpu_shorthand="off" + +# CPU Usage display +# Set CPU usage display setting +# --cpu_display bar, infobar, barinfo, off cpu_display="off" # CPU Cores @@ -111,6 +115,7 @@ cpu_display="off" cpu_cores="on" + # GPU # Shorten output of the getgpu funcion diff --git a/neofetch b/neofetch index d1111355..e36cb951 100755 --- a/neofetch +++ b/neofetch @@ -47,6 +47,7 @@ printinfo () { info "GPU" gpu info "Memory" memory + info "CPU Usage" cpu_usage # info "Disk" disk # info "Battery" battery # info "Font" font @@ -111,10 +112,14 @@ shell_version="off" # scaling_current, scaling_min, scaling_max speed_type="max" -# CPU Display -# Set shorthand setting and progress bar setting -# --cpu_display (name, speed, tiny, on, off) (bar, infobar, barinfo, off) +# CPU Shorthand +# Set shorthand setting +# --cpu_shorthand name, speed, tiny, on, off cpu_shorthand="off" + +# CPU Usage display +# Set CPU usage display setting +# --cpu_display bar, infobar, barinfo, off cpu_display="off" # CPU Cores @@ -1147,22 +1152,50 @@ getcpu () { [ "$cpu" ] && prin "$subtitle" "$cpu" - if [ "$cpu_display" != "off" ]; then - cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" - cpu_usage=$((${cpu_usage/\.*} / cores)) - - case "$cpu_display" in - "info") prin "$subtitle Usage" "${cpu_usage}%" ;; - "bar") prin "$subtitle Usage" "$(bar "$cpu_usage" 100)" ;; - "infobar") prin "$subtitle Usage" "${cpu_usage}% $(bar $cpu_usage 100)" ;; - "barinfo") prin "$subtitle Usage" "$(bar $cpu_usage 100) ${cpu_usage}%" ;; - esac - fi [ "$stdout_mode" != "on" ] && unset cpu } # }}} +# CPU Usage {{{ + +getcpu_usage () { + case "$os" in + "Linux" | "Mac OS X" | "iPhone OS") + # Get cores if unset + if [ -z "$cores" ]; then + case "$os" in + "Linux") cores="$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)" ;; + "Mac OS X") cores="$(sysctl -n hw.ncpu)" ;; + esac + fi + + cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" + cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))" + ;; + + "Windows") + cpu_usage="$(wmic cpu get loadpercentage /value)" + cpu_usage="${cpu_usage/LoadPercentage'='}" + ;; + + "BSD") + # BSD support coming soon. + return + ;; + esac + + # Print the bar + case "$cpu_display" in + "info") cpu_usage="${cpu_usage}%" ;; + "bar") cpu_usage="$(bar $cpu_usage 100)" ;; + "infobar") cpu_usage="${cpu_usage}% $(bar $cpu_usage 100)" ;; + "barinfo") cpu_usage="$(bar $cpu_usage 100) ${cpu_usage}%" ;; + esac +} + +# }}} + # GPU {{{ getgpu () { @@ -2972,9 +3005,8 @@ usage () { cat << EOF --progress_length num Length in spaces to make the progress bars. --progress_colors num num Colors to make the progress bar. Set in this order: elapsed, total - --cpu_display mode1 mode2 Which shorthand to use and how CPU usage should be printed - mode1 takes: name, speed, tiny, on, off - mode2 takes: info, bar, infobar, barinfo + --cpu_display mode Which way should the cpu progress bar be added + Takes bar, infobar, barinfo --memory_display mode Which way should the memory progress bar be added Takes bar, infobar, barinfo --battery_display mode Which way should the battery progress bar be added @@ -3119,10 +3151,7 @@ while [ "$1" ]; do progress_color_elapsed="$2" progress_color_total="$3" ;; - --cpu_display) - cpu_shorthand="$2" - cpu_display="$3" - ;; + --cpu_display) cpu_display="$2" ;; --memory_display) memory_display="$2" ;; --battery_display) battery_display="$2" ;; --disk_display) disk_display="$2" ;; From c3ddcaa331f385f5ab3381f8333c8241207b6ec6 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:23:57 +1000 Subject: [PATCH 03/15] --test: Include cpu usage --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index e36cb951..ba8cd8eb 100755 --- a/neofetch +++ b/neofetch @@ -3229,7 +3229,7 @@ while [ "$1" ]; do esac ;; --test) - info=(title underline distro kernel uptime packages shell resolution de wm wmtheme theme icons cpu gpu memory font disk battery song localip publicip users birthday term termfont) + info=(title underline distro kernel uptime packages shell resolution de wm wmtheme theme icons cpu cpu_usage gpu memory font disk battery song localip publicip users birthday term termfont) refresh_rate="on" shell_version="on" From 8e8ac505cad2673e56fc79720a7f21d4f1fd1635 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:26:21 +1000 Subject: [PATCH 04/15] Fix spacing on windows --- neofetch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index ba8cd8eb..82fb7b37 100755 --- a/neofetch +++ b/neofetch @@ -2545,6 +2545,7 @@ stdout () { *) "get$func" 2>/dev/null eval output="\$$func" + output="$(trim "$output")" stdout+="${output}${stdout_separator}" ;; esac @@ -2803,7 +2804,7 @@ getlinebreak () { # '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace. trim() { set -f - builtin echo -E ${1//[[:space:]]/ } + builtin echo -E ${1//$'\n'/ } set +f } From ac9c0a80c74b7a528e6269893b1af6603f729edd Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:28:31 +1000 Subject: [PATCH 05/15] Fix whitespace on Windows --- neofetch | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 82fb7b37..e5c48cfb 100755 --- a/neofetch +++ b/neofetch @@ -2799,12 +2799,9 @@ getlinebreak () { # # The 'set -f/+f' is here so that 'echo' doesn't cause any expansion # of special characters. -# -# The whitespace trim doesn't work with multiline strings so we use -# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace. trim() { set -f - builtin echo -E ${1//$'\n'/ } + builtin echo -En $1 set +f } From dd82e6de24788867ad4c14e2423796b13819cf4d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:32:20 +1000 Subject: [PATCH 06/15] Fix whitespace take 2 --- neofetch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index e5c48cfb..d349495d 100755 --- a/neofetch +++ b/neofetch @@ -2801,7 +2801,8 @@ getlinebreak () { # of special characters. trim() { set -f - builtin echo -En $1 + builtin echo -En ${1// +} set +f } From 4a3de0c8aeba6b8c83b2762cf6e9a1bd06674098 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:40:31 +1000 Subject: [PATCH 07/15] Fixed whitespace for realsies this time --- neofetch | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index d349495d..53193a08 100755 --- a/neofetch +++ b/neofetch @@ -1177,6 +1177,7 @@ getcpu_usage () { "Windows") cpu_usage="$(wmic cpu get loadpercentage /value)" cpu_usage="${cpu_usage/LoadPercentage'='}" + cpu_usage="${cpu_usage// }" ;; "BSD") @@ -2799,10 +2800,12 @@ getlinebreak () { # # The 'set -f/+f' is here so that 'echo' doesn't cause any expansion # of special characters. +# +# The whitespace trim doesn't work with multiline strings so we use +# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace. trim() { set -f - builtin echo -En ${1// -} + builtin echo -E ${1//[[:space:]]/ } set +f } From 82143f471275269a0dd9aea2950d2a9730836e1d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:42:16 +1000 Subject: [PATCH 08/15] Fuck wmic --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 53193a08..be6f64ca 100755 --- a/neofetch +++ b/neofetch @@ -1177,7 +1177,7 @@ getcpu_usage () { "Windows") cpu_usage="$(wmic cpu get loadpercentage /value)" cpu_usage="${cpu_usage/LoadPercentage'='}" - cpu_usage="${cpu_usage// }" + cpu_usage="${cpu_usage//[[:space:]]}" ;; "BSD") From 5a976e9d453beb32c984dcdb623aad4ba5fb220c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:45:06 +1000 Subject: [PATCH 09/15] Remove stray newline --- config/config | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config b/config/config index 533b8e3d..4a6cbdfe 100644 --- a/config/config +++ b/config/config @@ -115,7 +115,6 @@ cpu_display="off" cpu_cores="on" - # GPU # Shorten output of the getgpu funcion From d3c2216f4817991089b93bea85c22e504fb2ab18 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 20:46:13 +1000 Subject: [PATCH 10/15] Add CPU Usage comments --- config/config | 1 + neofetch | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/config b/config/config index 4a6cbdfe..6a491572 100644 --- a/config/config +++ b/config/config @@ -35,6 +35,7 @@ printinfo () { info "GPU" gpu info "Memory" memory + # info "CPU Usage" cpu_usage # info "Disk" disk # info "Battery" battery # info "Font" font diff --git a/neofetch b/neofetch index be6f64ca..c85e59b0 100755 --- a/neofetch +++ b/neofetch @@ -47,7 +47,7 @@ printinfo () { info "GPU" gpu info "Memory" memory - info "CPU Usage" cpu_usage + # info "CPU Usage" cpu_usage # info "Disk" disk # info "Battery" battery # info "Font" font From 1be5423b1ddb62e07a231bc177e8b53188ecd802 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 21:21:32 +1000 Subject: [PATCH 11/15] Fix usage on BSD --- neofetch | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/neofetch b/neofetch index c85e59b0..8a0f4c04 100755 --- a/neofetch +++ b/neofetch @@ -1161,28 +1161,23 @@ getcpu () { getcpu_usage () { case "$os" in - "Linux" | "Mac OS X" | "iPhone OS") - # Get cores if unset - if [ -z "$cores" ]; then - case "$os" in - "Linux") cores="$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)" ;; - "Mac OS X") cores="$(sysctl -n hw.ncpu)" ;; - esac - fi - - cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" - cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))" - ;; - "Windows") cpu_usage="$(wmic cpu get loadpercentage /value)" cpu_usage="${cpu_usage/LoadPercentage'='}" cpu_usage="${cpu_usage//[[:space:]]}" ;; - "BSD") - # BSD support coming soon. - return + "Linux" | "Mac OS X" | "iPhone OS" | "BSD") + # Get cores if unset + if [ -z "$cores" ]; then + case "$os" in + "Linux") cores="$(awk -F ': ' '/siblings/ {printf $2; exit}' /proc/cpuinfo)" ;; + "Mac OS X" | "BSD") cores="$(sysctl -n hw.ncpu)" ;; + esac + fi + + cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" + cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))" ;; esac From 57a0ed4d5d8d288f1464183df16870b24fcf0dc3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 21:42:53 +1000 Subject: [PATCH 12/15] Update usage --- README.md | 16 ++++++++-------- neofetch | 16 ++++++++-------- neofetch.1 | 26 ++++++++++++-------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 6e507f0f..850257ed 100644 --- a/README.md +++ b/README.md @@ -405,14 +405,14 @@ alias fetch2="fetch \ --progress_length num Length in spaces to make the progress bars. --progress_colors num num Colors to make the progress bar. Set in this order: elapsed, total - --cpu_display mode Which way should the cpu progress bar be added - Takes bar, infobar, barinfo - --memory_display mode Which way should the memory progress bar be added - Takes bar, infobar, barinfo - --battery_display mode Which way should the battery progress bar be added - Takes bar, infobar, barinfo - --disk_display mode Which way should the disk progress bar be added - Takes bar, infobar, barinfo, perc + --cpu_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --memory_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --battery_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --disk_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off Image: diff --git a/neofetch b/neofetch index 8a0f4c04..78964edb 100755 --- a/neofetch +++ b/neofetch @@ -3002,14 +3002,14 @@ usage () { cat << EOF --progress_length num Length in spaces to make the progress bars. --progress_colors num num Colors to make the progress bar. Set in this order: elapsed, total - --cpu_display mode Which way should the cpu progress bar be added - Takes bar, infobar, barinfo - --memory_display mode Which way should the memory progress bar be added - Takes bar, infobar, barinfo - --battery_display mode Which way should the battery progress bar be added - Takes bar, infobar, barinfo - --disk_display mode Which way should the disk progress bar be added - Takes bar, infobar, barinfo, perc + --cpu_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --memory_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --battery_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off + --disk_display mode Progress bar mode. + Takes: bar, infobar, barinfo, off Image: diff --git a/neofetch.1 b/neofetch.1 index 51f273a0..cb4e0b17 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -145,27 +145,25 @@ Colors to make the progress bar. .br Set in this order: elapsed, total .TP -.B \--cpu_display 'mode1' 'mode2' -Which shorthand to use and how CPU usage should be printed +.B \--cpu_display 'mode' +Progress bar mode. .br -mode1 takes: name, speed, tiny, on, off -.br -mode2 takes: info, bar, infobar, barinfo +Takes: bar, infobar, barinfo, off .TP -.B \--memory_display 'mode' -Which way should the memory progress bar be added +.B \--memory_display 'mode' +Progress bar mode. .br -Takes: bar, infobar, barinfo +Takes: bar, infobar, barinfo, off .TP -.B \--battery_display 'mode' -Which way should the battery progress bar be added +.B \--battery_display 'mode' +Progress bar mode. .br -Takes: bar, infobar, barinfo +Takes: bar, infobar, barinfo, off .TP -.B \--disk_display mode -Which way should the disk progress bar be added +.B \--disk_display 'mode' +Progress bar mode. .br -Takes: bar, infobar, barinfo, perc +Takes: bar, infobar, barinfo, off .SH IMAGE .TP From 758f883eb9ad0becc96a76c9e144f664cfb5cbdb Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 22:22:59 +1000 Subject: [PATCH 13/15] Update comments --- neofetch | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 78964edb..26e2ccf0 100755 --- a/neofetch +++ b/neofetch @@ -117,11 +117,6 @@ speed_type="max" # --cpu_shorthand name, speed, tiny, on, off cpu_shorthand="off" -# CPU Usage display -# Set CPU usage display setting -# --cpu_display bar, infobar, barinfo, off -cpu_display="off" - # CPU Cores # Display CPU cores in output # --cpu_cores on/off @@ -294,9 +289,11 @@ progress_color_total="distro" # barinfo: The bar is displayed before the info. # off: Only the info is displayed. # +# --cpu_display bar/infobar/barinfo/off # --memory_display bar/infobar/barinfo/off # --battery_display bar/infobar/barinfo/off # --disk_display bar/infobar/barinfo/off +cpu_display="off" memory_display="off" battery_display="off" disk_display="off" From 9f28c025bb70b94e442244c749404175394f6fa2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 22:33:34 +1000 Subject: [PATCH 14/15] Condense awk command --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 26e2ccf0..79756962 100755 --- a/neofetch +++ b/neofetch @@ -1173,7 +1173,7 @@ getcpu_usage () { esac fi - cpu_usage="$(ps aux | awk 'BEGIN { sum = 0 } { sum += $3 }; END { print sum }')" + cpu_usage="$(ps aux | awk 'BEGIN {sum=0} {sum+=$3 }; END {print sum}')" cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))" ;; esac From 59e0a166a2d725c4be27835c84d33f6008dedba9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 13 Jun 2016 22:37:11 +1000 Subject: [PATCH 15/15] Changelog --- 1.8.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/1.8.md b/1.8.md index 0922e839..458d3d54 100644 --- a/1.8.md +++ b/1.8.md @@ -76,6 +76,12 @@ block will be. - [Cmus] The function now works on both OS X and Linux. - [iTunes] Fix song not displaying. **[@iandrewt](https://github.com/iandrewt)** +**CPU Usage**
+ +- Fixed broken CPU usage output on BSD and Windows +- Fixed misleading output on Linux / Mac OS X +- Moved CPU Usage to its own dedicated function + ### Image