blob: 9b7c2a7631346c13432845610546a8dadc4c2b64 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/env bash
version=0.4
SYSTEMPONIES=/usr/share/ponies
HOMEPONIES="${HOME}/.ponies"
pony=
cmd=cowsay
[[ ${0} == *ponythink ]] && cmd=cowthink
version() {
echo "ponysay v$version"
}
usage() {
version
echo
echo "Usage:"
echo "${0##*/} [options]"
echo
echo "Options:"
echo " -v Show version and exit"
echo " -h Show this help and exit"
echo " -f[name] Select a pony (Either a filename or a pony name)"
}
while getopts f:hv OPT
do
case ${OPT} in
v) version; exit ;;
h) usage; exit ;;
f) pony=$OPTARG ;;
\?) usage; exit 1 ;;
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
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
export PERL_UNICODE=S
exec "$cmd" -f "$pony"
|