#!/usr/bin/env bash version=0.7 SYSTEMPONIES=/usr/share/ponies HOMEPONIES="${HOME}/.ponies" pony="*" wrap= cmd=cowsay [[ ${0} == *ponythink ]] && cmd=cowthink version() { echo "ponysay v$version" } list() { echo "ponyfiles located in $SYSTEMPONIES:" ls -1 $SYSTEMPONIES | sed "s/.pony//" if [[ -d $HOMEPONIES ]]; then echo "ponyfiles located in $HOMEPONIES:" ls -1 $HOMEPONIES | sed "s/.pony//" fi } usage() { version cat </dev/null || ./ponysaytruncater `tput cols || echo 0` 2>/dev/null || cat) } while getopts f:W:lhv OPT do case ${OPT} in v) version; exit ;; h) usage; exit ;; f) pony="$OPTARG" ;; l) list; exit ;; W) wrap="$OPTARG" ;; \?) usage >&2; exit 1 ;; esac done shift $((OPTIND - 1)) if ! hash $cmd &>/dev/null; then cat >&2 <&2 "All the ponies are missing! Call the Princess!" exit 1 fi # Choose a random pony pony="${ponies[$RANDOM%${#ponies[@]}]}" fi if [[ -n "$*" ]]; then # Handle a message given via arguments say <<<"$*" else say fi