From 1b356da175e030a3170f524d2d0cf7e95655a5ac Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:04:25 +0200 Subject: [PATCH 1/5] ascii: Added support for command output --- neofetch | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index 5f1eb181..6ced94d3 100755 --- a/neofetch +++ b/neofetch @@ -3418,8 +3418,9 @@ image_backend() { get_ascii() { if [[ -f "$image_source" && ! "$image_source" =~ (png|jpg|jpeg|jpe|svg|gif) ]]; then ascii_data="$(< "$image_source")" - else - err "Ascii: Ascii file not found, using distro ascii." + + elif [[ "$image_source" != "auto" ]]; then + ascii_data="$image_source" fi # Set locale to get correct padding. @@ -3430,6 +3431,9 @@ get_ascii() { ((++lines,${#line}>ascii_length)) && ascii_length="${#line}" done <<< "${ascii_data//\$\{??\}}" + # Fallback if file not found. + ((lines==1)) && { image_source="auto"; get_distro_ascii; get_ascii; return; } + # Colors. ascii_data="${ascii_data//\$\{c1\}/$c1}" ascii_data="${ascii_data//\$\{c2\}/$c2}" @@ -4595,7 +4599,6 @@ get_args() { "--ascii_distro") image_backend="ascii" ascii_distro="$2" - case "$2" in "-"* | "") ascii_distro="$distro" ;; esac ;; "--ascii_bold") ascii_bold="$2" ;; From 4fb30c040a8bd11f557877c8576789e95f4b0688 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:09:10 +0200 Subject: [PATCH 2/5] ascii: Added support for command output --- neofetch | 6 +++++- neofetch.1 | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 6ced94d3..f4c19a52 100755 --- a/neofetch +++ b/neofetch @@ -4375,8 +4375,12 @@ IMAGE BACKEND: 'sixel', 'tycat', 'w3m' --source source Which image or ascii file to use. Possible values: 'auto', 'ascii', 'wallpaper', '/path/to/img', - '/path/to/ascii', '/path/to/dir/' + '/path/to/ascii', '/path/to/dir/', 'command output' [ascii] + --ascii source Shortcut to use 'ascii' backend. + + NEW: neofetch --ascii \"\$(fortune | cowsay -W 30)\" + --caca source Shortcut to use 'caca' backend. --iterm2 source Shortcut to use 'iterm2' backend. --jp2a source Shortcut to use 'jp2a' backend. diff --git a/neofetch.1 b/neofetch.1 index ae57b426..2bf66158 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -1,5 +1,5 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.7. -.TH NEOFETCH "1" "October 2018" "Neofetch 5.0.1" "User Commands" +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. +.TH NEOFETCH "1" "January 2019" "Neofetch 5.0.1" "User Commands" .SH NAME Neofetch \- A fast, highly customizable system info script .SH SYNOPSIS @@ -199,10 +199,12 @@ Possible values: 'ascii', 'caca', 'jp2a', 'iterm2', 'off', \fB\-\-source\fR source Which image or ascii file to use. Possible values: 'auto', 'ascii', 'wallpaper', '/path/to/img', -\&'/path/to/ascii', '/path/to/dir/' +\&'/path/to/ascii', '/path/to/dir/', 'command output' [ascii] .TP \fB\-\-ascii\fR source Shortcut to use 'ascii' backend. +.IP +NEW: neofetch \fB\-\-ascii\fR "$(fortune | cowsay \fB\-W\fR 30)" .TP \fB\-\-caca\fR source Shortcut to use 'caca' backend. From defee48d14d93ab4f2fc4a34f375586b1e84a905 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:09:55 +0200 Subject: [PATCH 3/5] ascii: Added support for command output --- neofetch | 1 + 1 file changed, 1 insertion(+) diff --git a/neofetch b/neofetch index f4c19a52..c6f092b9 100755 --- a/neofetch +++ b/neofetch @@ -660,6 +660,7 @@ image_backend="ascii" # # Default: 'auto' # Values: 'auto', 'ascii', 'wallpaper', '/path/to/img', '/path/to/ascii', '/path/to/dir/' +# 'command output (neofetch --ascii "$(fortune | cowsay -W 30)")' # Flag: --source # # NOTE: 'auto' will pick the best image source for whatever image backend is used. From b399f49077a98790ab52b5c70efba5dc39120835 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:17:56 +0200 Subject: [PATCH 4/5] ascii: Fixed bug when files named auto or ascii were found. --- neofetch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index c6f092b9..bf120339 100755 --- a/neofetch +++ b/neofetch @@ -3417,12 +3417,12 @@ image_backend() { } get_ascii() { - if [[ -f "$image_source" && ! "$image_source" =~ (png|jpg|jpeg|jpe|svg|gif) ]]; then - ascii_data="$(< "$image_source")" - - elif [[ "$image_source" != "auto" ]]; then - ascii_data="$image_source" - fi + [[ ! "$image_source" =~ (ascii|auto) ]] && + if [[ -f "$image_source" && ! "$image_source" =~ (png|jpg|jpeg|jpe|svg|gif) ]]; then + ascii_data="$(< "$image_source")" + else + ascii_data="$image_source" + fi # Set locale to get correct padding. LC_ALL="$sys_locale" From c99b864590902ab61f61a6e4530b9b14208a475e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:34:20 +0200 Subject: [PATCH 5/5] ascii: Fixed bug when long line is input --- neofetch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index bf120339..3b56ea56 100755 --- a/neofetch +++ b/neofetch @@ -3429,11 +3429,11 @@ get_ascii() { # Calculate size of ascii file in line length / line count. while IFS=$'\n' read -r line; do - ((++lines,${#line}>ascii_length)) && ascii_length="${#line}" + ((++lines,${#line}>ascii_len)) && ascii_len="${#line}" done <<< "${ascii_data//\$\{??\}}" # Fallback if file not found. - ((lines==1)) && { image_source="auto"; get_distro_ascii; get_ascii; return; } + ((lines==1)) && { lines=; ascii_len=; image_source="auto"; get_distro_ascii; get_ascii; return; } # Colors. ascii_data="${ascii_data//\$\{c1\}/$c1}" @@ -3443,7 +3443,7 @@ get_ascii() { ascii_data="${ascii_data//\$\{c5\}/$c5}" ascii_data="${ascii_data//\$\{c6\}/$c6}" - ((text_padding=ascii_length+gap)) + ((text_padding=ascii_len+gap)) printf '%b\n' "$ascii_data${reset}" LC_ALL=C }