blob: 576a4e8cb2e1b90b7ed56e301e589ae792ac7623 (
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
|
#!/usr/bin/env bash
INSTALLDIR="$(dirname "$(dirname "$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")")" # Get main bash script directory's parent
if [ $# == 1 ] && ([ "$1" == '-l' ] || [ "$1" == '--list' ]); then
perl "$0.pl" "$INSTALLDIR" | cut -d @ -f 1 | uniq
else
_ponies="$(perl "$0.pl" "$INSTALLDIR")"
ponies=()
if (( $# > 0 )); then
p=()
for arg in "$@"; do
p+="$(echo "$_ponies" | grep "^$arg@") "
done
_ponies=$p
fi
ponies=( $_ponies )
if (( ${#ponies[@]} == 0 )); then
ponies=()
for arg in "$@"; do
ponies+=( "$arg" )
done
p="${ponies[$RANDOM%${#ponies[@]}]}"
q='I am totally speechless'
echo "-f" $p $q
else
pony="${ponies[$RANDOM%${#ponies[@]}]}"
p="$(echo $pony | cut -d '@' -f 1)"
f="$(echo $pony | cut -d '@' -f 2)"
q="$(cat "$INSTALLDIR/share/ponysay/quotes/$f")"
echo "-f" $p $q
fi
fi
|