Skip to content

Instantly share code, notes, and snippets.

@airvzxf
Last active July 28, 2023 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airvzxf/e3e01aa9959e2640d8c63344bbfe6d47 to your computer and use it in GitHub Desktop.
Save airvzxf/e3e01aa9959e2640d8c63344bbfe6d47 to your computer and use it in GitHub Desktop.
Given a font, it will display all the character sets it contains.
#!/usr/bin/env bash
# Thanks for this code Lu Xu.
# https://stackoverflow.com/a/60475015/1727383
# Make this file executable.
# chmod u+x ls-chars.bash
# Usage:
# ./ls-chars.bash "FontAwesome"
# Check the list of installed fonts.
# fc-match --all | grep --color=always -ins awesome
# It needs the package: 'fontconfig'.
# Output the hexadecimal value of the character.
# printf "%06X\n" \"\"
# Inverse operation:
# echo "\UF2DC "
count=0
for range in $(fc-match --format='%{charset}\n' "${1}"); do
for n in $(seq "0x${range%-*}" "0x${range#*-}"); do
printf "%05x\n" "${n}"
done
done | while read -r n_hex; do
count=$((count + 1))
printf "%-6s\U${n_hex} | " "${n_hex}"
[ $((count % 10)) = 0 ] && printf "\n"
done
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment