ponysay/ponysay

38 lines
1 KiB
Text
Raw Normal View History

2012-02-26 17:43:26 +01:00
#!/usr/bin/env bash
2012-02-26 16:47:05 +01:00
export PERL_UNICODE=S
2012-02-26 16:55:57 +01:00
2012-02-26 18:28:03 +01:00
[[ -z ${PONYDIR} ]] && PONYDIR=/usr/share/ponies
HOMEDIR=${HOME}/.ponies
cmd=cowsay
[[ ${0} == *ponythink ]] && cmd=cowthink
2012-02-26 16:47:05 +01:00
function ponyf() {
2012-02-26 19:47:19 +01:00
if [[ -f ${HOMEDIR}/${1}.pony ]]; then
${cmd} -f "${HOMEDIR}/${1}.pony" $@
elif [[ -f ${PONYDIR}/${1}.pony ]]; then
${cmd} -f "${PONYDIR}/${1}.pony" $@
2012-02-26 16:47:05 +01:00
else
2012-02-26 17:02:57 +01:00
ponyr $@
2012-02-26 16:47:05 +01:00
fi
}
function ponyr() {
2012-02-26 19:47:19 +01:00
if [[ -d ${HOMEDIR} ]] && [[ -n $(find ${HOMEDIR} -name \*.pony) ]]; then
${cmd} -f $(ls ${HOMEDIR}/*.pony | sort -R | head -n1) $@
elif [[ -d ${PONYDIR} ]] && [[ -n $(find ${PONYDIR} -name \*.pony) ]]; then
${cmd} -f $(ls ${PONYDIR}/*.pony | sort -R | head -n1) $@
2012-02-26 18:28:03 +01:00
fi
2012-02-26 16:47:05 +01:00
}
while getopts f:hv OPT
do
case ${OPT} in
2012-02-26 19:47:19 +01:00
v) echo "ponysay v0.2" ; exit;;
2012-02-26 20:48:52 +01:00
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;;
2012-02-26 16:55:57 +01:00
f) ponyf $* ; exit;;
2012-02-26 17:02:57 +01:00
\?) echo "DERP"; exit;;
2012-02-26 16:55:57 +01:00
*) ponyr $* ; exit;;
2012-02-26 16:47:05 +01:00
esac
done
2012-02-26 16:55:57 +01:00
ponyr $*