#!/usr/bin/env bash version=1.0 SYSTEMPONIES="/usr/share/ponysay/ponies" HOMEPONIES="${HOME}/.ponysay/ponies" pony="*" wrap="" if [ "$TERM" = "linux" ]; then SYSTEMPONIES="/usr/share/ponysay/ttyponies" HOMEPONIES="${HOME}/.ponysay/ttyponies" fi cmd=cowsay [[ ${0} == *ponythink ]] && cmd=cowthink version() { echo "ponysay v$version" } list() { scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` listcmd=$(echo $0 | sed -e 's/\/ponysay$/\//g' -e 's/\/ponythink$/\//g')"ponysaylist.pl" echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed "s/.pony//" | sort) if [[ -d $HOMEPONIES ]]; then echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed "s/.pony//" | sort) fi } usage() { version cat </dev/null || ${HOME}/.local/bin/ponysaytruncater $WIDTH 2>/dev/null || ./ponysaytruncater $WIDTH 2>/dev/null || cat fi } if [ "$PONYSAY_SHELL_LINES" = "" ]; then PONYSAY_SHELL_LINES=2 fi function htrunchead { head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) } function htrunctail { tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) } if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail else exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead fi else exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc fi } ponies=() while getopts f:W:lhv OPT do case ${OPT} in v) version; exit ;; h) usage; exit ;; f) ponies+=( "$OPTARG" ) ;; l) list; exit ;; W) wrap="$OPTARG" ;; \?) usage >&2; exit 1 ;; esac done shift $((OPTIND - 1)) hash $cmd &>/dev/null; if [ $? -ne 0 ]; 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