aboutsummaryrefslogtreecommitdiff
path: root/ponysay
blob: ddaf7d02fcc554517fad01d8813be349e881dd22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
export PERL_UNICODE=S

[[ -z ${PONYDIR} ]] && PONYDIR=/usr/share/ponies
HOMEDIR=${HOME}/.ponies

cmd=cowsay
[[ ${0} == *ponythink ]] && cmd=cowthink

function ponyf() {
    if [[ -f ${HOMEDIR}/${1}.cow ]]; then
        ${cmd} -f "${HOMEDIR}/${1}.cow" $@
    elif [[ -f ${PONYDIR}/${1}.cow ]]; then
        ${cmd} -f "${PONYDIR}/${1}.cow" $@
    else
        ponyr $@
    fi
}
function ponyr() {
    if [[ -d ${HOMEDIR} ]] && [[ -n $(find ${HOMEDIR} -name \*.cow) ]]; then
        ${cmd} -f $(ls ${HOMEDIR}/*.cow | sort -R | head -n1) $@
    elif [[ -d ${PONYDIR} ]] && [[ -n $(find ${PONYDIR} -name \*.cow) ]]; then
        ${cmd} -f $(ls ${PONYDIR}/*.cow | sort -R | head -n1) $@
    fi
}

while getopts f:hv OPT
do
    case ${OPT} in
	v)  echo "v0.1" ; exit;;
	h)  echo "helpherpderp" ; exit;;
	f)  ponyf $* ; exit;;
	\?) echo "DERP"; exit;;
	*)  ponyr $* ; exit;;
    esac
done
ponyr $*