I am trying to create something like neofetch does using bash.
I want to show one image on the right and one ascii art (using the cat << EOF myascii EOF command) So that I can show a logo and a text on the other side.
I want to use it as my login welcome screen when I ssh some of my machines.
So I was able to show the ascii art by doing :
cat << EOF
_____ _
|_ _| | |
| | ___ ___| |_
| |/ _ \/ __| __|
| | __/\__ \ |_
\_/\___||___/\__|
EOF
And showing my image using catimg myimage.png
However I try to show them both side by side. I tried using pr.
pr -m -t <(catimg) <(cat mytestfile.txt)
but it doesn't work and it cuts my ascii art.
It's the same using the paste command.
Was anyone able to do it. If yes how ? My ascii art is quiet long too so without it to be cutted it would be awesome.
Thanks for your help.
catimg
and figlet
Instead of real merge, I will simply put both output at correct place by using ANSI escape code
{
mapfile aa < <(figlet -w40 $text)
printf "%s" "${aa[@]}"
catimg -w40 "$image" |
sed "\$!s/^/\o33[40C/;1s/^/\o33[${#aa[@]}A/"
} >outputfile.txt
This could be written as a function:
mkTextImage() {
local aa width=${COLUMNS} prcent=50 text image lwidth rwidth ffont
while [ "${1::1}" == "-" ] ;do
case $1 in
-w) shift;width=$1;shift;;
-p) shift;prcent=$1;shift;;
-f) shift;ffont="-f $1";shift;;
esac
done
text="$1" image="$2"
printf -v lwidth %.0f $(
bc -l <<<"$width/100*$prcent")
rwidth=$((width-lwidth))
mapfile aa < <(figlet -w$lwidth $ffont $text)
printf "%s" "${aa[@]}"
catimg -w$rwidth "$image" |
sed "\$!s/^/\o33[${lwidth}C/;1s/^/\o33[${#aa[@]}A/"
}
And reversed:
(Nota: This work while catimg length stay bigger than figlet length)
mkImageText () {
local aa fl width=${COLUMNS} prcent=50 text image lwidth rwidth ffont
while [ "${1::1}" == "-" ] ;do
case $1 in
-w) shift;width=$1;shift;;
-p) shift;prcent=$1;shift;;
-f) shift;ffont="-f $1";shift;;
esac
done
image="$1" text="$2"
printf -v lwidth %.0f $(bc -l <<<"$width/100*$prcent")
rwidth=$((width-lwidth))
mapfile aa < <(catimg -w$lwidth "$image")
printf "%s" "${aa[@]}"
printf "\e[$((${#aa[@]}-1))A"
mapfile fl < <(figlet -w$rwidth $ffont "$text")
printf "\e[${lwidth}C%s" "${fl[@]}"
printf "\e[$((${#aa[@]}-${#fl[@]}-1))B"
}
From there, regarding your comment: try using 42%
of 80 columns width for image:
mkImageText -f small -p 42 spongebob.png "Sponge Bob"
or
mkTextImage -f small -p 58 "Sponge Bob" spongebob.png
Will render:
Then you could try using -f smblock
option, or modify functions to use toilet
instead of figlet
...
More complete version on my website: mkImageText.sh