Skip to content

Instantly share code, notes, and snippets.

@gatlin
Last active January 12, 2023 16:09
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 gatlin/7f88d32b61090d3cc1d95a366781e04d to your computer and use it in GitHub Desktop.
Save gatlin/7f88d32b61090d3cc1d95a366781e04d to your computer and use it in GitHub Desktop.
unicode character viewer. download the unicode data txt file here: https://github.com/latex3/unicode-data/blob/main/UnicodeData.txt
#!/usr/bin/env bash
############################
# Unicode Character Viewer #
# v1.0 #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Author: Gatlin Johnson #
# <gatlin@niltag.net> #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Runtime dependencies: #
# - fzf #
# - xclip #
# - perl / awk / grep #
# - toilet (optional) #
############################
UNICODE_DATA=${UNICODE_DATA:="$HOME/Documents/UnicodeData.txt"}
function viewcodepoint {
CODEPOINT="${1}"
CHAR=$(perl -X -e "print pack qq(W*), 0x${CODEPOINT}")
echo "${CHAR}"
if command -v toilet &> /dev/null; then
toilet $CODEPOINT
toilet -f bigascii12 "${CHAR}"
else
echo "Codepoint: $CODEPOINT"
fi
}
export -f viewcodepoint
cat "${UNICODE_DATA}" | \
grep -vE '<control>' | \
awk -v FS=';' \
'BEGIN { printf "Codepoint\tDescription\tCategory\tNotes\n" } \
{ printf "%s\t%s\t%s\t%s\n", $1, $2, $3, $11 }' | \
fzf --delimiter='\t' -n1,2 --reverse -i \
--tabstop 24 \
--with-nth=2,3 \
--header-lines 1 \
--preview-label "╢ unicode character viewer ╟" \
--preview-window "left,35" \
--preview 'bash -c "viewcodepoint {1}" && echo {4}' | \
cut -f1 | \
xargs -I{} perl -X -e "print pack qq(W*), 0x{}" | \
xclip -sel clip
@gatlin
Copy link
Author

gatlin commented Jan 12, 2023

2023-01-12-090548_782x722_scrot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment