Ciglet: Figlet Comment Blocks
I often use FIGlet in code comments; if a file I'm working on is particulary large and hairy, big comments can provide useful visual landmarks as you scroll around.
I also like to leave myself a big old temporary
// _____ ___ ____ ___
// |_ _/ _ \| _ \ / _ \
// | || | | | | | | | | |
// | || |_| | |_| | |_| |
// |_| \___/|____/ \___/
at the end of the day with some notes about where I left off.
You can easily pipe figlet's output to the pasteboard on MacOS like:
% figlet TODO | pbcopy
...but got tired enough of typing | pbcopy
, pasting, and then having to select the newly pasted text and comment it out that I hacked together a Bash script that wraps the figlet
command and:
- Accepts an additional initial
-a
argument (a for add) for the comment character you want to use (Defaults to//
) - Passes any additional arguments directly to figlet
- Pipes the output of
figlet
intosed
to add the comment prefix to each line - Pipes the output of that onto the pasteboard so you can just paste it into your editor. (It also prints it to STDOUT.)
#!/bin/bash
# _______ __ __
# / ____(_)___ _/ /__ / /_
# / / / / __ `/ / _ \/ __/
# / /___/ / /_/ / / __/ /_
# \____/_/\__, /_/\___/\__/
# /____/
#
# Figlet Code Comments (MacOS)
# Default prefix
prefix="//"
# Check for -a option first
if [[ "$1" == "-a" && -n "$2" ]]; then
prefix="$2"
shift 2
fi
# Escape the prefix for sed
escaped_prefix=$(echo "$prefix" | sed 's/[\/&]/\\&/g')
# Run figlet with all remaining arguments, add prefix, and send to both stdout and pbcopy
figlet "$@" | sed "s/^/$escaped_prefix /" | tee >(pbcopy)
echo ""
echo "(Copied to clipboard)"
If you save it to an executable file called ciglet
somewhere in your PATH, you can run:
ciglet -a '#' -f slant 'Hello, World!'
and you should see
# __ __ ____ _ __ __ ____
# / / / /__ / / /___ | | / /___ _____/ /___/ / /
# / /_/ / _ \/ / / __ \ | | /| / / __ \/ ___/ / __ / /
# / __ / __/ / / /_/ / | |/ |/ / /_/ / / / / /_/ /_/
# /_/ /_/\___/_/_/\____( ) |__/|__/\____/_/ /_/\__,_(_)
# |/
(Copied to clipboard)
Thu Feb 20 2025 19:00:00 GMT-0500 (Eastern Standard Time)