#!/usr/bin/env bash # Ponies use UTF-8 drawing characters. Prevent a Perl warning. export PERL_UNICODE=S SYSTEMPONIES=/usr/share/ponies HOMEPONIES="${HOME}/.ponies" cmd=cowsay [[ ${0} == *ponythink ]] && cmd=cowthink pony= while getopts f:hv OPT do case ${OPT} in v) echo "ponysay v0.4" ; exit;; h) echo "-v for version, -h for this, -f to specify a ponyfile. It'll choose a random ponyfile if no argument is given." ; exit;; f) pony=$OPTARG ;; \?) echo "DERP"; exit;; esac done # Pony not a file? Search for it if [[ ! -f $pony ]]; then # Pony not set? Choose all [[ -z $pony ]] && pony="*" ponies=() [[ -d $SYSTEMPONIES ]] && ponies+=( "$SYSTEMPONIES"/$pony.pony ) [[ -d $HOMEPONIES ]] && ponies+=( "$HOMEPONIES"/$pony.pony ) if (( ${#ponies} < 1 )); then echo >&2 "All the ponies are missing! Call the Princess!" exit 1 fi # Choose a random pony pony="${ponies[$RANDOM%${#ponies[@]}]}" fi exec "$cmd" -f "$pony"