#!/usr/bin/env bash version=0.9 SYSTEMPONIES=/usr/share/ponies HOMEPONIES="${HOME}/.ponies" pony="*" wrap= if [ "$TERM" = "linux" ]; then SYSTEMPONIES=/usr/share/ttyponies HOMEPONIES="${HOME}/.ttyponies" fi 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 || ${HOME}/.local/bin/ponysaytruncater `tput cols || echo 0` 2>/dev/null || ./ponysaytruncater `tput cols || echo 0` 2>/dev/null || cat fi } function htrunc { if [ "$PONYSAY_SHELL_LINES" = "" ]; then PONYSAY_SHELL_LINES=2 fi head --lines=$(( $(stty size <&2 | cut -d ' ' -f 1) - $PONYSAY_SHELL_LINES )) } if [ "$TERM" = "linux" ]; then if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | tac | htrunc | tac else exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunc fi else exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc fi } 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