Last active
July 31, 2021 14:39
-
-
Save HunterKohler/5fc8379a0f885973f6563c26b53f4296 to your computer and use it in GitHub Desktop.
Very simple cowsay
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 | |
set -e | |
say() { | |
local -r msg=$(tr -d "\n" <<<"$@") | |
local -ir len=${#msg} | |
local hr pad | |
printf -v hr -- "-%.0s" $(seq $((len > 40 ? 42 : len + 2))) | |
printf -v pad -- "%$((40 - len % 40))s" | |
if ((len <= 40)); then | |
printf " %s\n < %s >\n %s" "$hr" "$msg" "$hr" | |
elif ((len <= 80)); then | |
printf " %s\n/ %s \\ \n" "$hr" "${msg:0:40}" | |
printf "\\ %s%s /\n %s" "${msg:40}" "$pad" "$hr" | |
else | |
printf " %s\n/ %s \\ \n" "$hr" "${msg:0:40}" | |
for ((i = 40; i + 40 < len; i += 40)); do | |
printf "| %s |\n" "${msg:i:40}" | |
done | |
printf "\\ %s%s /\n %s" "${msg:$((len - len % 40))}" "$pad" "$hr" | |
fi | |
echo -e " | |
\t \ ^__^ | |
\t \ (oo)\_______ | |
\t (__)\ )\/\\ | |
\t ||----w | | |
\t || || | |
" | |
} | |
main() { | |
if (($# == 0)); then | |
say "..." | |
exit 1 | |
fi | |
say "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment