Wednesday, January 08, 2025

Bash script to show demo of all fonts on Linux

 I found this script somewhere, it makes a nice HTML file showing a demo of all your fonts.  I made some small tweaks to the script so it works better.  Here is a screen shot and the code below.  Save it as fonts.sh then chmod +x the file and run it.  Will output fonts.html that looks like this




#!/usr/bin/env bash

cat > fonts.html << __HEADER
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Sample of local fonts matching '$1'</title>
</head>
<body>
__HEADER

fc-list --format='%{family}\n' $1 | cut -d ',' -f 1 | sort -u | while IFS='' read -r fontfamily
do
    cat >> fonts.html << __BODY
    <hr/>
    <div style="font-family: '${fontfamily}', 'serif'">
        <h1>${fontfamily}</h1>
        <p>
            1lLiI -0O- == {} [] The quick brown fox jumped over the lazy brown dog<br/>
            0123456789,.:;?/<>'"[]{}|\-=\`~!@#$%^&*()-=\\
        </p>
    </div>
__BODY

done

cat >> fonts.html << __FOOTER
    <hr/>
</body>
</html>
__FOOTER

echo "fonts.html created"

No comments:

//]]>