Skip to content

Instantly share code, notes, and snippets.

@fetwar
Last active May 7, 2024 01:23
Show Gist options
  • Save fetwar/c595c3894547bfe7510545f53546dda6 to your computer and use it in GitHub Desktop.
Save fetwar/c595c3894547bfe7510545f53546dda6 to your computer and use it in GitHub Desktop.
Print a heading padded with equals signs above and below
#!/usr/bin/env bash
# Usage:
# print-padded-heading Some Heading
#
# Outputs:
# ==============
# Some Heading
# ==============
# sed explination:
# h; copy pattern to hold space
# s; replace any pattern char with =
# p; print pattern (now all =)
# H; append pattern to hold
# x; swap pattern and hold
# sed then auto prints the pattern again.
# To indent the heading, pad the echo as desired
print-padded-heading() {
echo " $* " | sed 'h; s/./=/g; p; H; x'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment