Created
March 8, 2018 23:40
-
-
Save rawiriblundell/a544f5cdb366218933a5cc6bb33bb133 to your computer and use it in GitHub Desktop.
A function to provide cowsay functionality on hosts that don't have it
This file contains hidden or 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
if ! command -v cowsay &>/dev/null; then | |
cowsay() { | |
local msg | |
if [[ -t 0 ]] && [[ -z $1 ]]; then | |
msg="Moo! What should I say?" | |
elif [[ -n $1 ]]; then | |
msg="$*" | |
else | |
msg=$(paste -sd ' ' - | sed -e "s/[[:space:]]\\+/ /g") | |
fi | |
curl "http://cowsay.morecode.org/say?format=text&message=${msg// /%20}" | |
printf -- '%s\n' "" | |
} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment