From 5c6b680a1eddaa6e17827993fb985ed09fea016b Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 29 Mar 2016 17:57:22 +1100 Subject: [PATCH 1/5] Get ascii size in a single wc call --- neofetch | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index 20617e12..1eee8d36 100755 --- a/neofetch +++ b/neofetch @@ -1852,15 +1852,14 @@ getascii () { export LC_ALL="$SYS_LOCALE" # Turn the file into a variable and strip escape codes. - ascii_strip=$(<"$ascii") + ascii_strip=$(<"${ascii}") ascii_strip=${ascii_strip//\$\{??\}} ascii_strip=${ascii_strip//\\} # Get length of longest line - length="$(wc -L 2>/dev/null <<< "$ascii_strip")" - - # Get the height in lines - lines="$(($(wc -l 2>/dev/null <<< "$ascii_strip") + 1))" + ascii_size=($(wc -lL 2>/dev/null <<< "$ascii_strip")) + ascii_length=${ascii_size[0]} + ascii_height=${ascii_size[1]} # Fallback to using awk on systems without 'wc -L' [ -z "$length" ] && \ @@ -2851,7 +2850,7 @@ if [ "$image" != "off" ]; then [ -z "$info_height" ] && info_height=0 # Set cursor position dynamically based on height of ascii/text. - [ "$lines" -lt "$info_height" ] && lines="$info_height" + [ "$ascii_length" -lt "$info_height" ] && lines="$info_height" printf "%b%s" "\033[${lines}H\033[${prompt_height}A" fi From a1d409046a23cb3fd6667c80ed4dbf9220906e54 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 29 Mar 2016 18:04:36 +1100 Subject: [PATCH 2/5] Rename variables so they're clearer --- neofetch | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/neofetch b/neofetch index 1eee8d36..e1bec84a 100755 --- a/neofetch +++ b/neofetch @@ -1858,14 +1858,14 @@ getascii () { # Get length of longest line ascii_size=($(wc -lL 2>/dev/null <<< "$ascii_strip")) - ascii_length=${ascii_size[0]} - ascii_height=${ascii_size[1]} + ascii_height=${ascii_size[0]} + ascii_length=${ascii_size[1]} # Fallback to using awk on systems without 'wc -L' - [ -z "$length" ] && \ - length="$(awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")" + [ -z "$ascii_length" ] && \ + ascii_length="$(awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")" - padding="\033[$((length + gap))C" + padding="\033[$((ascii_length + gap))C" printf "%b%s" "$print" export LC_ALL=C @@ -2850,9 +2850,9 @@ if [ "$image" != "off" ]; then [ -z "$info_height" ] && info_height=0 # Set cursor position dynamically based on height of ascii/text. - [ "$ascii_length" -lt "$info_height" ] && lines="$info_height" + [ "$ascii_height" -lt "$info_height" ] && ascii_height="$info_height" - printf "%b%s" "\033[${lines}H\033[${prompt_height}A" + printf "%b%s" "\033[${ascii_height}H\033[${prompt_height}A" fi # Re-enable line wrap From 47eba4945758653ffa71464bb566b9e921a859f8 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 29 Mar 2016 18:17:30 +1100 Subject: [PATCH 3/5] Swap to a portable way of getting the ascii size' --- neofetch | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/neofetch b/neofetch index e1bec84a..4ebf52be 100755 --- a/neofetch +++ b/neofetch @@ -1857,14 +1857,10 @@ getascii () { ascii_strip=${ascii_strip//\\} # Get length of longest line - ascii_size=($(wc -lL 2>/dev/null <<< "$ascii_strip")) + ascii_size=($(awk 'END {print NR}length>max{max=length}END{print max}' <<< "$ascii_strip")) ascii_height=${ascii_size[0]} ascii_length=${ascii_size[1]} - # Fallback to using awk on systems without 'wc -L' - [ -z "$ascii_length" ] && \ - ascii_length="$(awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")" - padding="\033[$((ascii_length + gap))C" printf "%b%s" "$print" From 213f23c7c4882d8a1584547a8c3c45326764bff0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 29 Mar 2016 18:19:34 +1100 Subject: [PATCH 4/5] Add +1 to the height --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 4ebf52be..e20d641f 100755 --- a/neofetch +++ b/neofetch @@ -1858,7 +1858,7 @@ getascii () { # Get length of longest line ascii_size=($(awk 'END {print NR}length>max{max=length}END{print max}' <<< "$ascii_strip")) - ascii_height=${ascii_size[0]} + ascii_height=$((${ascii_size[0]} + 1)) ascii_length=${ascii_size[1]} padding="\033[$((ascii_length + gap))C" From feb2a32db1adaa8e04b0111f613ba57e638bcdb5 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 29 Mar 2016 18:20:48 +1100 Subject: [PATCH 5/5] Remove pointless brackets --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index e20d641f..2d03d97a 100755 --- a/neofetch +++ b/neofetch @@ -1852,7 +1852,7 @@ getascii () { export LC_ALL="$SYS_LOCALE" # Turn the file into a variable and strip escape codes. - ascii_strip=$(<"${ascii}") + ascii_strip=$(<"$ascii") ascii_strip=${ascii_strip//\$\{??\}} ascii_strip=${ascii_strip//\\}