From 2edad96936c14a856ca6f0e7a670e045e3f55538 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 13:51:21 +1100 Subject: [PATCH 1/8] Fix huge whitespace in CPU output --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index a3b76be4..9bf99351 100755 --- a/neofetch +++ b/neofetch @@ -839,7 +839,7 @@ getcpu () { "Mac OS X") cpu="$(sysctl -n machdep.cpu.brand_string)" - cpu=${cpu/ } + cpu=${cpu//[[:space:]]/ } cores=$(sysctl -n hw.ncpu) ;; From 6296cf7410f6218aec6b8003c140099eded273ec Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 14:05:22 +1100 Subject: [PATCH 2/8] Use tr on OSX to trim whitespace --- neofetch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 9bf99351..6627df2f 100755 --- a/neofetch +++ b/neofetch @@ -838,8 +838,7 @@ getcpu () { ;; "Mac OS X") - cpu="$(sysctl -n machdep.cpu.brand_string)" - cpu=${cpu//[[:space:]]/ } + cpu="$(sysctl -n machdep.cpu.brand_string | tr -s \ )" cores=$(sysctl -n hw.ncpu) ;; From 423af0cd481b9f928070251b9ad7461c77d62758 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 14:13:27 +1100 Subject: [PATCH 3/8] Use extended globbing instead of tr --- neofetch | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index 6627df2f..072d5e34 100755 --- a/neofetch +++ b/neofetch @@ -430,8 +430,9 @@ config_file="$HOME/.config/neofetch/config" # Gather Info {{{ -# Set no case match +# Set no case match and extended globbing. shopt -s nocasematch +shopt -s extglob # Operating System {{{ @@ -838,7 +839,8 @@ getcpu () { ;; "Mac OS X") - cpu="$(sysctl -n machdep.cpu.brand_string | tr -s \ )" + cpu="$(sysctl -n machdep.cpu.brand_string)" + cpu=${cpu//+( )/ } cores=$(sysctl -n hw.ncpu) ;; From 5f2047fd0bc835241a8bc54ab40188777254ba00 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 14:50:00 +1100 Subject: [PATCH 4/8] More reliable whitespace removal --- neofetch | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/neofetch b/neofetch index 072d5e34..b041fce1 100755 --- a/neofetch +++ b/neofetch @@ -458,7 +458,6 @@ case "$os" in "Linux" ) if type -p lsb_release >/dev/null 2>&1; then distro="$(lsb_release -d 2>/dev/null | awk -F ':' '/Description/ {printf $2}')" - distro=${distro/[[:space:]]} elif type -p crux >/dev/null 2>&1; then distro="$(crux)" @@ -504,8 +503,6 @@ case "$os" in # Strip crap from the output of wmic distro=${distro/Caption'='} - distro=${distro//[[:space:]]/ } - distro=${distro// } distro=${distro/Microsoft } # Change bits to xx-bit for Windows @@ -513,6 +510,7 @@ case "$os" in x32="32-bit" ;; esac +distro=${distro//+( )/ } ascii_distro="$distro" getdistro () { @@ -555,12 +553,10 @@ getuptime () { case "$distro" in *"Puppy"* | "Quirky Werewolf"* | "Alpine Linux"* | "Windows"*) uptime=$(uptime | awk -F ':[0-9]{2}+ |(, ){1}+' '{printf $2}') - uptime=${uptime/ / } ;; "openSUSE"*) uptime=$(uptime | awk -F ':[0-9]{2}+[a-z][a-z] |(, ){1}+' '{printf $2}') - uptime=${uptime/ / } ;; *) @@ -631,6 +627,7 @@ getuptime () { uptime=${uptime# } ;; esac + uptime=${uptime//+( )/ } } # }}} @@ -840,7 +837,6 @@ getcpu () { "Mac OS X") cpu="$(sysctl -n machdep.cpu.brand_string)" - cpu=${cpu//+( )/ } cores=$(sysctl -n hw.ncpu) ;; @@ -851,8 +847,6 @@ getcpu () { cpu="$(sysctl -n hw.model)" cpu=${cpu/[0-9]\.*} cpu=${cpu/ @*} - cpu=${cpu// } - cpu=${cpu% } # Get cpu speed case "$distro" in @@ -868,8 +862,6 @@ getcpu () { 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)" @@ -895,11 +887,11 @@ getcpu () { cpu=${cpu//(TM)} cpu=${cpu//(r)} cpu=${cpu//(R)} - cpu=${cpu// CPU} - cpu=${cpu// Processor} - cpu=${cpu// Six-Core} - cpu=${cpu// Eight-Core} - cpu=${cpu// with Radeon HD Graphics} + cpu=${cpu//CPU} + cpu=${cpu//Processor} + cpu=${cpu//Six-Core} + cpu=${cpu//Eight-Core} + cpu=${cpu//with Radeon HD Graphics} # Add cpu cores to output [ "$cpu_cores" == "on" ] && [ ! -z "$cores" ] && \ @@ -927,6 +919,9 @@ getcpu () { ;; esac + # Trim whitespace + cpu=${cpu//+( )/ } + # Add CPU info bar prin "${subtitle}: ${cpu}" @@ -1012,7 +1007,6 @@ getgpu () { nvidia*) gpu=${gpu/NVIDIA Corporation } - gpu=${gpu/nVidia Corporation } gpu=${gpu/G????M } gpu=${gpu/G???? } gpu=${gpu/\[} @@ -1041,8 +1035,6 @@ getgpu () { gpu=$(pciconf -lv 2>/dev/null | grep -B 4 "VGA" | grep "device") gpu=${gpu/device*= } gpu=${gpu//\'} - gpu=${gpu//[[:space:]]/ } - gpu=${gpu// } ;; esac ;; @@ -1078,6 +1070,7 @@ getgpu () { ;; esac + gpu=${gpu//+( )/ } gpu="${gpu}${count}" } @@ -1726,7 +1719,7 @@ getbirthday () { # Pretty output [ "$birthday_shorthand" == "off" ] && \ - birthday="${date_cmd/ / }" + birthday=${date_cmd//+( )/ } # Toggle showing the time [ "$birthday_time" == "off" ] && \ From ea1d2d2341b9c12aa8a0107219b7477a1572472f Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 14:56:43 +1100 Subject: [PATCH 5/8] Also remove trailing tab characters --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index b041fce1..5b26f118 100755 --- a/neofetch +++ b/neofetch @@ -510,7 +510,7 @@ case "$os" in x32="32-bit" ;; esac -distro=${distro//+( )/ } +distro=${distro//+([[:space:]])/ } ascii_distro="$distro" getdistro () { @@ -627,7 +627,7 @@ getuptime () { uptime=${uptime# } ;; esac - uptime=${uptime//+( )/ } + uptime=${uptime//+([[:space:]])/ } } # }}} @@ -920,7 +920,7 @@ getcpu () { esac # Trim whitespace - cpu=${cpu//+( )/ } + cpu=${cpu//+([[:space:]])/ } # Add CPU info bar prin "${subtitle}: ${cpu}" @@ -1070,7 +1070,7 @@ getgpu () { ;; esac - gpu=${gpu//+( )/ } + gpu=${gpu//+([[:space:]])/ } gpu="${gpu}${count}" } @@ -1719,7 +1719,7 @@ getbirthday () { # Pretty output [ "$birthday_shorthand" == "off" ] && \ - birthday=${date_cmd//+( )/ } + birthday=${date_cmd//+([[:space:]])/ } # Toggle showing the time [ "$birthday_time" == "off" ] && \ From df945f51a9cf63cc3123d65f30661979c45b4325 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 14:59:49 +1100 Subject: [PATCH 6/8] Revert tab changes --- neofetch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 5b26f118..3afe9817 100755 --- a/neofetch +++ b/neofetch @@ -458,6 +458,7 @@ case "$os" in "Linux" ) if type -p lsb_release >/dev/null 2>&1; then distro="$(lsb_release -d 2>/dev/null | awk -F ':' '/Description/ {printf $2}')" + distro=${distro/[[:space:]]} elif type -p crux >/dev/null 2>&1; then distro="$(crux)" @@ -510,7 +511,7 @@ case "$os" in x32="32-bit" ;; esac -distro=${distro//+([[:space:]])/ } +distro=${distro//+( )/ } ascii_distro="$distro" getdistro () { @@ -627,7 +628,7 @@ getuptime () { uptime=${uptime# } ;; esac - uptime=${uptime//+([[:space:]])/ } + uptime=${uptime//+( )/ } } # }}} @@ -920,7 +921,7 @@ getcpu () { esac # Trim whitespace - cpu=${cpu//+([[:space:]])/ } + cpu=${cpu//+( )/ } # Add CPU info bar prin "${subtitle}: ${cpu}" @@ -1070,7 +1071,7 @@ getgpu () { ;; esac - gpu=${gpu//+([[:space:]])/ } + gpu=${gpu//+( )/ } gpu="${gpu}${count}" } @@ -1719,7 +1720,7 @@ getbirthday () { # Pretty output [ "$birthday_shorthand" == "off" ] && \ - birthday=${date_cmd//+([[:space:]])/ } + birthday=${date_cmd//+( )/ } # Toggle showing the time [ "$birthday_time" == "off" ] && \ From 19b3c22b37caa48fa42201aec61868ac656663f3 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 15:09:59 +1100 Subject: [PATCH 7/8] Fix windows whitespace --- neofetch | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neofetch b/neofetch index 3afe9817..2fb22c1c 100755 --- a/neofetch +++ b/neofetch @@ -504,6 +504,8 @@ case "$os" in # Strip crap from the output of wmic distro=${distro/Caption'='} + distro=${distro//[[:space:]]/ } + distro=${distro// } distro=${distro/Microsoft } # Change bits to xx-bit for Windows @@ -863,6 +865,8 @@ getcpu () { 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)" From 0805fb5e3a39ebff6958826b095a6ba1a65e8823 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 27 Mar 2016 15:21:11 +1100 Subject: [PATCH 8/8] Fix bugs with OpenBSD --- neofetch | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 2fb22c1c..915c9592 100755 --- a/neofetch +++ b/neofetch @@ -1486,6 +1486,7 @@ getdisk () { *"BSD") case "$distro" in "FreeBSD"*) df_flags="-h -c -l" ;; + *) return ;; esac ;; esac @@ -1589,7 +1590,8 @@ getbattery () { battery0now=$(sysctl -n hw.sensors.acpibat0.watthour3) battery0now="${battery0now/ Wh*}" - battery="$(printf "%s\n" "100 * $battery0now / $battery0full" | bc)%" + [ ! -z "$battery0full" ] && \ + battery="$(printf "%s\n" "100 * $battery0now / $battery0full" | bc)%" ;; "Mac OS X")