Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
bin: Add fontview.sh
Browse files Browse the repository at this point in the history
It's mature enough to replicate to my work computer, it's mature enough
for my dots.
  • Loading branch information
h3xx committed Sep 23, 2021
1 parent ce31148 commit 823d3d9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions home/bin/fontview.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

HELP_MESSAGE() {
local EXIT_CODE="${1:-0}"
cat <<EOF
Usage: $(basename -- "$0") [OPTIONS] [--] FILE...
Display an image of a font file.
-h Show this help message.
-t TEXT Show TEXT instead of default.
-- Terminate options list.
Copyright (C) 2015 Dan Church.
License GPLv3+: GNU GPL version 3 or later (http://gnu.org/licenses/gpl.html).
This is free software: you are free to change and redistribute it. There is NO
WARRANTY, to the extent permitted by law.
EOF
exit "$EXIT_CODE"
}

TEXT=''

while getopts 't:h' flag; do
case "$flag" in
'h')
HELP_MESSAGE 0
;;
't')
TEXT="$OPTARG"
;;
*)
HELP_MESSAGE 1
;;
esac
done

shift "$((OPTIND-1))"

TEMP_FILES=()

cleanup() {
rm -rf -- "${TEMP_FILES[@]}"
}

trap 'cleanup' EXIT

fontimage_args=()

if [ -n "$TEXT" ]; then
fontimage_args+=(--text "$TEXT")
fi

temp_dir="$(mktemp -d -t "$(basename -- "$0").XXXXXX")"
# XXX : fontimage requires .png extension
temp="$temp_dir/fontimage.png"
TEMP_FILES+=("$temp_dir")

for fn; do

echo "$fn"
fontimage "${fontimage_args[@]}" -o "$temp" "$fn" &&
xv "$temp"
done

0 comments on commit 823d3d9

Please sign in to comment.