From 440153e7d8b014dce8222743afe082e1a5f4cb11 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:14:59 +1100 Subject: [PATCH 1/6] CPU: Don't simplify option names for no reason --- config/config | 7 ++++--- neofetch | 11 ++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/config/config b/config/config index 219d51b3..53b809b5 100644 --- a/config/config +++ b/config/config @@ -134,11 +134,12 @@ shell_version="on" # CPU speed type # -# Default: 'bios' -# Values: 'current', 'min', 'max', 'bios', +# Default: 'bios_limit' +# Values: 'scaling_cur_freq', 'scaling_min_freq', 'scaling_max_freq', 'bios_limit'. # Flag: --speed_type # Supports: Linux with 'cpufreq' -speed_type="bios" +# NOTE: Any file in '/sys/devices/system/cpu/cpu0/cpufreq' can be used as a value. +speed_type="bios_limit" # Shorten the output of the CPU function # diff --git a/neofetch b/neofetch index 655b873b..b057f4a2 100755 --- a/neofetch +++ b/neofetch @@ -734,23 +734,16 @@ get_cpu() { "Android"*) cpu="$(getprop ro.product.board)" ;; *) cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)" ;; esac + speed_dir="/sys/devices/system/cpu/cpu0/cpufreq" temp_dir="/sys/class/hwmon/hwmon0/temp1_input" # Get cpu speed if [[ -d "$speed_dir" ]]; then - case "$speed_type" in - "current") speed_type="scaling_cur_freq" ;; - "min") speed_type="scaling_min_freq" ;; - "max") speed_type="scaling_max_freq" ;; - "bios") speed_type="bios_limit" ;; - esac - - # Fallback to cpuinfo_max_freq if $speed_type fails + # Fallback to bios_limit if $speed_type fails. speed="$(< "${speed_dir}/${speed_type}")" || \ speed="$(< "${speed_dir}/bios_limit")" || \ speed="$(< "${speed_dir}/scaling_max_freq")" - speed="$((speed / 100000))" else From fdc350f136d5dd89605d1856d8590607a5037cd0 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:22:02 +1100 Subject: [PATCH 2/6] General: Add warnings speed_type options --- neofetch | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/neofetch b/neofetch index b057f4a2..42df3b1c 100755 --- a/neofetch +++ b/neofetch @@ -2989,18 +2989,25 @@ old_functions() { fi } -old_flags() { +old_options() { [[ -n "$osx_buildversion" ]] && err "Config: \$osx_buildversion is deprecated, use \$distro_shorthand instead." - [[ -n "$osx_codename" ]] && err "Config: \$osx_codename is deprecated, use \$distro_shorthand instead." - [[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead." - [[ -n "$image" ]] && { err "Config: \$image is deprecated, use \$image_source instead."; image_source="$image"; } + [[ -n "$osx_codename" ]] && err "Config: \$osx_codename is deprecated, use \$distro_shorthand instead." + [[ "$cpu_cores" == "on" ]] && err "Config: cpu_cores='on' is deprecated, use cpu_cores='logical|physical|off' instead." + [[ -n "$image" ]] && { err "Config: \$image is deprecated, use \$image_source instead."; image_source="$image"; } # All progress_ variables were changed to bar_ - [[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$bar_char_elapsed and \$bar_char_total instead." - [[ -n "$progress_border" ]] && err "Config: \$progress_border is deprecated, use \$bar_border instead." - [[ -n "$progress_length" ]] && err "Config: \$progress_length is deprecated, use \$bar_length instead." + [[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$bar_char_elapsed and \$bar_char_total instead." + [[ -n "$progress_border" ]] && err "Config: \$progress_border is deprecated, use \$bar_border instead." + [[ -n "$progress_length" ]] && err "Config: \$progress_length is deprecated, use \$bar_length instead." [[ -n "$progress_color_elapsed" ]] && err "Config: \$progress_color_elapsed is deprecated, use \$bar_color_elapsed instead." - [[ -n "$progress_color_total" ]] && err "Config: \$progress_color_total is deprecated, use \$bar_color_total instead." + [[ -n "$progress_color_total" ]] && err "Config: \$progress_color_total is deprecated, use \$bar_color_total instead." + + # All cpufreq values were changed in 2.1.0. + # 'current', 'min', 'max', 'bios' + [[ "$speed_type" == "current" ]] && err "Config: speed_type='current' is deprecated, use speed_type='scaling_cur_freq' instead." + [[ "$speed_type" == "min" ]] && err "Config: speed_type='min' is deprecated, use speed_type='scaling_min_freq' instead." + [[ "$speed_type" == "max" ]] && err "Config: speed_type='max' is deprecated, use speed_type='scaling_max_freq' instead." + [[ "$speed_type" == "bios" ]] && err "Config: speed_type='bios' is deprecated, use speed_type='bios_limit' instead." } cache_uname() { @@ -3325,7 +3332,7 @@ main() { get_os get_default_config 2>/dev/null get_args "$@" - old_flags + old_options get_distro get_bold get_distro_colors From 5a6a3d7e5bdb4db5981c38d53640d15b48889de3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:33:19 +1100 Subject: [PATCH 3/6] CPU: [NetBSD] Remove case statement in favor of 1 line test --- neofetch | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/neofetch b/neofetch index 42df3b1c..eae5befd 100755 --- a/neofetch +++ b/neofetch @@ -723,9 +723,7 @@ get_cpu() { # NetBSD emulates the linux /proc filesystem instead of using sysctl for hw # information so we have to use this block below which temporarily sets the # OS to 'Linux' for the duration of this function. - case "$distro" in - "NetBSD"*) local os="Linux" ;; - esac + [[ "$distro" == "NetBSD"* ]] && local os="Linux" case "$os" in "Linux" | "Windows") From f7686ee8e89080c7209393e6fbb044c6cb93da2d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:40:29 +1100 Subject: [PATCH 4/6] CPU: Update comments --- neofetch | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/neofetch b/neofetch index eae5befd..60d90d3b 100755 --- a/neofetch +++ b/neofetch @@ -727,7 +727,7 @@ get_cpu() { case "$os" in "Linux" | "Windows") - # Get cpu name + # Get CPU name case "$distro" in "Android"*) cpu="$(getprop ro.product.board)" ;; *) cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)" ;; @@ -736,7 +736,7 @@ get_cpu() { speed_dir="/sys/devices/system/cpu/cpu0/cpufreq" temp_dir="/sys/class/hwmon/hwmon0/temp1_input" - # Get cpu speed + # Get CPU speed if [[ -d "$speed_dir" ]]; then # Fallback to bios_limit if $speed_type fails. speed="$(< "${speed_dir}/${speed_type}")" || \ @@ -749,14 +749,14 @@ get_cpu() { speed="$((speed / 100))" fi - # Get cpu temp + # 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 + # Get CPU cores case "$cpu_cores" in "logical" | "on") cores="$(grep -c "^processor" /proc/cpuinfo)" ;; "physical") cores="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)" ;; @@ -766,7 +766,7 @@ get_cpu() { "Mac OS X") cpu="$(sysctl -n machdep.cpu.brand_string)" - # Show/hide hyperthreaded cores + # Get CPU cores case "$cpu_cores" in "logical" | "on") cores="$(sysctl -n hw.logicalcpu_max)" ;; "physical") cores="$(sysctl -n hw.physicalcpu_max)" ;; @@ -801,20 +801,20 @@ get_cpu() { ;; "BSD") - # Get cpu name + # Get CPU name cpu="$(sysctl -n hw.model)" cpu="${cpu/[0-9]\.*}" cpu="${cpu/ @*}" - # Get cpu speed + # Get CPU speed speed="$(sysctl -n hw.cpuspeed)" [[ -z "$speed" ]] && speed="$(sysctl -n hw.clockrate)" speed="$((speed / 100))" - # Get cpu cores + # Get CPU cores cores="$(sysctl -n hw.ncpu)" - # Get cpu temp + # Get CPU temp if [[ "$cpu_temp" == "on" ]]; then case "$kernel_name" in "FreeBSD"* | "DragonFly"*) @@ -830,17 +830,17 @@ get_cpu() { ;; "Solaris") - # Get cpuname + # Get CPU name cpu="$(psrinfo -pv)" cpu="${cpu//*$'\n'}" cpu="${cpu/[0-9]\.*}" cpu="${cpu/ @*}" - # Get cpu speed + # Get CPU speed speed="$(psrinfo -v | awk '/operates at/ {print $6; exit}')" speed="$((speed / 100))" - # Show/hide hyperthreaded cores + # Get CPU cores case "$cpu_cores" in "logical" | "on") cores="$(kstat -m cpu_info | grep -c -F "chip_id")" ;; "physical") cores="$(psrinfo -p)" ;; @@ -848,11 +848,16 @@ get_cpu() { ;; "Haiku") + # Get CPU name cpu="$(sysinfo -cpu | awk -F '\\"' '/CPU #0/ {print $2}')" cpu="${cpu/@*}" + + # Get CPU speed speed="$(sysinfo -cpu | awk '/running at/ {print $NF; exit}')" speed="${speed/MHz}" speed="$((speed / 100))" + + # Get CPU cores cores="$(sysinfo -cpu | grep -c -F 'CPU #')" ;; esac @@ -906,9 +911,7 @@ get_cpu() { cpu="${cpu/Core? Duo }" cpu="${cpu/AMD }" - case "$cpu_shorthand" in - "tiny") cpu="${cpu/@*}" ;; - esac + [[ "$cpu_shorthand" == "tiny" ]] && cpu="${cpu/@*}" ;; esac } From dc08df12ac2bb61f8fbfde95e864c28256355a8d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:45:33 +1100 Subject: [PATCH 5/6] CPU: Simplify format check --- neofetch | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/neofetch b/neofetch index 60d90d3b..e1f38a5f 100755 --- a/neofetch +++ b/neofetch @@ -862,26 +862,19 @@ get_cpu() { ;; esac - # Format the output - case "$os" in - "Mac OS X" | "iPhone OS") ;; - *) - # Fix for speeds under 1ghz - if [[ -z "${speed:1}" ]]; then - speed="0.${speed}" - else - speed="${speed:0:1}.${speed:1}" - fi + # Fix for speeds under 1ghz + if [[ "$speed" ]]; then + if [[ -z "${speed:1}" ]]; then + speed="0.${speed}" + else + speed="${speed:0:1}.${speed:1}" + fi - cpu="$cpu @ ${speed}GHz $temp" - ;; - esac + cpu="$cpu @ ${speed}GHz $temp" + fi # Remove uneeded patterns from cpu output - # This is faster than sed/gsub - cpu="${cpu//(tm)}" cpu="${cpu//(TM)}" - cpu="${cpu//(r)}" cpu="${cpu//(R)}" cpu="${cpu//CPU}" cpu="${cpu//Processor}" From 4413c0f210e603a0cbea25d21c9af6838b490311 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 14 Dec 2016 11:57:02 +1100 Subject: [PATCH 6/6] CPU: Remove duplicate substitutions --- neofetch | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index e1f38a5f..d9eb9f8e 100755 --- a/neofetch +++ b/neofetch @@ -899,10 +899,9 @@ get_cpu() { "speed") cpu="${cpu#*@ }" ;; "on" | "tiny") - cpu="${cpu/Intel }" - cpu="${cpu/Core }" - cpu="${cpu/Core? Duo }" cpu="${cpu/AMD }" + cpu="${cpu/Intel }" + cpu="${cpu/Core? Duo }" [[ "$cpu_shorthand" == "tiny" ]] && cpu="${cpu/@*}" ;;