From f18c315697bfd84e7ef9112a086163b6daeb060a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 10:18:35 +1000 Subject: [PATCH 1/9] Fix whitespace in Windows OS line --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index d5d44c92..34f29b4b 100755 --- a/neofetch +++ b/neofetch @@ -538,7 +538,7 @@ getdistro () { distro=${distro/Microsoft } ;; esac - distro=${distro//+( )/ } + distro="${distro%"${distro##*[![:space:]]}"}" # Get architecture [ "$os_arch" == "on" ] && \ From f855ae243217ac18ee7bad017818aea0810ea91d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:06:35 +1000 Subject: [PATCH 2/9] Move all whitespace trimming to an external function --- neofetch | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/neofetch b/neofetch index 34f29b4b..683581aa 100755 --- a/neofetch +++ b/neofetch @@ -480,7 +480,6 @@ getdistro () { "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)" @@ -533,12 +532,9 @@ getdistro () { # Strip crap from the output of wmic distro=${distro/Caption'='} - distro=${distro//[[:space:]]/ } - distro=${distro// } distro=${distro/Microsoft } ;; esac - distro="${distro%"${distro##*[![:space:]]}"}" # Get architecture [ "$os_arch" == "on" ] && \ @@ -646,7 +642,6 @@ getuptime () { uptime=${uptime/minutes/mins} uptime=${uptime/minute/min} uptime=${uptime/seconds/secs} - uptime=${uptime# } ;; "tiny") @@ -659,10 +654,8 @@ getuptime () { uptime=${uptime/ minute/m} uptime=${uptime/ seconds/s} uptime=${uptime/,} - uptime=${uptime# } ;; esac - uptime=${uptime//+( )/ } } # }}} @@ -743,7 +736,6 @@ getpackages () { packages=$((packages+=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l))) ;; esac - packages=${packages// } } # }}} @@ -784,8 +776,6 @@ getshell () { shell+="$("$SHELL" -c 'printf "%s" "$FISH_VERSION"')" ;; esac - - shell="${shell/\(*\)}" fi } @@ -1180,9 +1170,6 @@ getcpu () { ;; esac - # Trim whitespace - cpu=${cpu//+( )/ } - [ ! -z "$cpu" ] && prin "$subtitle" "$cpu" if [ "$cpu_display" != "off" ]; then @@ -1219,7 +1206,6 @@ getgpu () { count="$(printf "%s" "$gpu" | uniq -c)" count=${count/ VGA*} count=${count/ 3D*} - count=${count//[[:space:]]} # If there's more than one gpu # Display the count. @@ -1366,8 +1352,6 @@ getgpu () { "Windows") gpu=$(wmic path Win32_VideoController get caption /value) gpu=${gpu/Caption'='} - gpu=${gpu//[[:space:]]/ } - gpu=${gpu// } ;; esac @@ -1393,7 +1377,6 @@ getgpu () { ;; esac - gpu=${gpu//+( )/ } gpu="${gpu}${count}" } @@ -1560,11 +1543,9 @@ getresolution () { "Windows") width=$(wmic path Win32_VideoController get CurrentHorizontalResolution /value 2>/dev/null) width=${width/CurrentHorizontalResolution'='/} - width=${width//[[:space:]]} height=$(wmic path Win32_VideoController get CurrentVerticalResolution /value 2>/dev/null) height=${height/CurrentVerticalResolution'='/} - height=${height//[[:space:]]} [ ! -z "$width" ] && \ resolution="${width}x${height}" @@ -1693,7 +1674,6 @@ getstyle () { gtk3theme=${gtk3theme/${name}*=} gtk3theme=${gtk3theme//\"} - gtk3theme=${gtk3theme/[[:space:]]/ } fi # Uppercase the first letter of each gtk theme @@ -1723,7 +1703,6 @@ getstyle () { theme="${gtk2theme}${gtk3theme}" theme=${theme//\"} theme=${theme//\'} - theme=${theme// / } # Make the output shorter by removing "[GTKX]" from the string if [ "$gtk_shorthand" == "on" ]; then @@ -1958,8 +1937,6 @@ getbattery () { "Windows") battery="$(wmic Path Win32_Battery get EstimatedChargeRemaining /value)" battery=${battery/EstimatedChargeRemaining'='} - battery=${battery//[[:space:]]/ } - battery=${battery// } [ ! -z "$battery" ] && \ battery+="%" ;; @@ -2496,6 +2473,9 @@ info () { # If the output is empty, don't print anything [ -z "$output" ] && return + # Trim whitespace + output="$(trim "$output")" + case "$1" in title) string="${title_color}${bold}${output}" @@ -2536,6 +2516,9 @@ prin () { length=$((${#subtitle} + ${#2} + 1)) fi + # Trim whitespace + string="$(trim "$string")" + # Print the info printf "%b%s\n" "${padding}${string}\033[0m" } @@ -2803,6 +2786,16 @@ getlinebreak () { # }}} +# Trim whitespace {{{ + +trim() { + set -f + builtin echo -E $1 + set +f +} + +# }}} + # }}} From 52a8cd491695d5d9ffcfc528c3ec1db93c74d267 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:11:34 +1000 Subject: [PATCH 3/9] Readd a substitution that shouldn't have been removed --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index 683581aa..dc8e7a6d 100755 --- a/neofetch +++ b/neofetch @@ -776,6 +776,7 @@ getshell () { shell+="$("$SHELL" -c 'printf "%s" "$FISH_VERSION"')" ;; esac + shell="${shell/\(*\)}" fi } From 8b0d6a2095a10e0a85ff1bef67a2b3190efda70a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:41:25 +1000 Subject: [PATCH 4/9] GTK Theme: Group subsitutions --- neofetch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index dc8e7a6d..c1677914 100755 --- a/neofetch +++ b/neofetch @@ -1614,7 +1614,6 @@ getstyle () { *"Cinnamon") if type -p gsettings >/dev/null 2>&1; then gtk3theme=$(gsettings get org.cinnamon.desktop.interface $gsettings) - gtk3theme=${gtk3theme//"'"} gtk2theme=${gtk3theme} fi ;; @@ -1622,7 +1621,6 @@ getstyle () { "Gnome"* | "Unity"* | "Budgie") if type -p gsettings >/dev/null 2>&1; then gtk3theme=$(gsettings get org.gnome.desktop.interface $gsettings) - gtk3theme=${gtk3theme//"'"} gtk2theme=${gtk3theme} elif type -p gconftool-2 >/dev/null 2>&1; then @@ -1654,7 +1652,6 @@ getstyle () { fi gtk2theme=${gtk2theme/${name}*=} - gtk2theme=${gtk2theme//\"} fi # Check for gtk3 theme @@ -1674,9 +1671,14 @@ getstyle () { fi gtk3theme=${gtk3theme/${name}*=} - gtk3theme=${gtk3theme//\"} fi + # Remove quotes + gtk2theme=${gtk2theme//\"} + gtk2theme=${gtk2theme//\'} + gtk3theme=${gtk3theme//\"} + gtk3theme=${gtk3theme//\'} + # Uppercase the first letter of each gtk theme if [ "$version" -ge 4 ]; then gtk2theme=${gtk2theme^} @@ -1702,8 +1704,6 @@ getstyle () { # Final string theme="${gtk2theme}${gtk3theme}" - theme=${theme//\"} - theme=${theme//\'} # Make the output shorter by removing "[GTKX]" from the string if [ "$gtk_shorthand" == "on" ]; then From dac32f3ab18e7c41caa7acaa86082e1ec23f7cc4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:45:33 +1000 Subject: [PATCH 5/9] Remove another pointless substitution --- neofetch | 1 - 1 file changed, 1 deletion(-) diff --git a/neofetch b/neofetch index c1677914..5faca9cd 100755 --- a/neofetch +++ b/neofetch @@ -1661,7 +1661,6 @@ getstyle () { elif type -p gsettings >/dev/null 2>&1; then gtk3theme="$(gsettings get org.gnome.desktop.interface $gsettings)" - gtk3theme=${gtk3theme//\'} elif [ -f "/usr/share/gtk-3.0/settings.ini" ]; then gtk3theme=$(grep "^[^#]*$name" /usr/share/gtk-3.0/settings.ini) From 64182e6ef763bc1d8c8a72777dbc53f7d020371c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:57:10 +1000 Subject: [PATCH 6/9] Whitespace trim, handle multiline strings --- neofetch | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 5faca9cd..27032b3f 100755 --- a/neofetch +++ b/neofetch @@ -2788,9 +2788,18 @@ getlinebreak () { # Trim whitespace {{{ +# When a string is passed to 'echo' all trailing and leading +# whitespace is removed and inside the string multiple spaces are +# condensed into single spaces. +# +# 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 + builtin echo -E ${1//[[:space:]]/ } set +f } From 34c89c05cc9c97fd327edc9fd34a66d29ea9f5af Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:59:21 +1000 Subject: [PATCH 7/9] Fix windows ascii logo --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index 27032b3f..ef4a95ee 100755 --- a/neofetch +++ b/neofetch @@ -2697,6 +2697,7 @@ colors () { "Windows"*) setcolors 1 2 4 3 + ascii_distro="windows" ;; "Raspbian"* | *) From 5d4e65ad5447404dc47dc964bcf8c47df0470f37 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 12:06:30 +1000 Subject: [PATCH 8/9] Trim '$ascii_distro' variable --- neofetch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neofetch b/neofetch index ef4a95ee..969fb434 100755 --- a/neofetch +++ b/neofetch @@ -2697,7 +2697,6 @@ colors () { "Windows"*) setcolors 1 2 4 3 - ascii_distro="windows" ;; "Raspbian"* | *) @@ -3281,7 +3280,7 @@ trap 'printf "\033[?25h"; clear; exit' 2 # Distro detection getdistro -[ -z "$ascii_distro" ] && ascii_distro="$distro" +[ -z "$ascii_distro" ] && ascii_distro="$(trim $distro)" # Get colors and bold bold From ba78e2c8888fa2ca9aa3fcacea4f532c42c0f74a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 12:10:10 +1000 Subject: [PATCH 9/9] Quote trim command --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 969fb434..0b04610d 100755 --- a/neofetch +++ b/neofetch @@ -3280,7 +3280,7 @@ trap 'printf "\033[?25h"; clear; exit' 2 # Distro detection getdistro -[ -z "$ascii_distro" ] && ascii_distro="$(trim $distro)" +[ -z "$ascii_distro" ] && ascii_distro="$(trim "$distro")" # Get colors and bold bold