Last active
May 7, 2024 01:23
-
-
Save fetwar/c595c3894547bfe7510545f53546dda6 to your computer and use it in GitHub Desktop.
Print a heading padded with equals signs above and below
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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