From 64182e6ef763bc1d8c8a72777dbc53f7d020371c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 12 Jun 2016 11:57:10 +1000 Subject: [PATCH] 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 }