Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created March 8, 2018 23:40
Show Gist options
  • Save rawiriblundell/a544f5cdb366218933a5cc6bb33bb133 to your computer and use it in GitHub Desktop.
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
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