#!/bin/sh -
# showfigfonts by Glenn Chappell <ggc@uiuc.edu>
# 12 Aug 1994
# Based on showfigfonts by Greg Galperin <grg@ai.mit.edu>, Nov 1993.
#
# Prints a list of available figlet fonts, along with a sample of each
# font.  If directory is given, lists fonts in that directory; otherwise
# uses the default font directory.  If word is given, prints that word
# in each font; otherwise prints the font name.
# 
# Usage: showfigfonts [ -d directory ] [ word ]

# Set up PATH so figlet can be found
PATH=$PATH:`dirname $0`

# Get figlet version
FIGLETVERSION=`figlet -I1 2>/dev/null`
if [ -z "$FIGLETVERSION" ]; then
  FIGLETVERSION=20000
fi

USAGE="Usage `basename $0` [ -d directory ] [ word ]"

while getopts d: c ; do
  case $c in
    d)     FONTDIR="$OPTARG";;
    \?)    echo $USAGE
           exit 1;;
  esac
done
shift `expr $OPTIND - 1`
WORD="$1"

if [ -z "$FONTDIR" ]; then
  if [ $FIGLETVERSION -lt 20100 ]; then
    # figlet 2.0
    FONTDIR="`figlet -F | sed -e '1d' -e '3,$d' -e 's/Font directory: //'`"
  else
    # figlet 2.1 or later
    FONTDIR="`figlet -I2`"
  fi
fi

cd "$FONTDIR"
for F in `ls *.flf | sed s/\.flf$//` ; do
  echo $F :
  if [ -n "$WORD" ]; then
    echo $WORD | figlet -d . -f $F
  else
    echo $F | figlet -d . -f $F
  fi
  echo "" ; echo ""
done
