ponysay/pq4ps

40 lines
894 B
Text
Raw Normal View History

2012-08-18 01:56:08 +02:00
#!/usr/bin/env bash
2012-08-01 00:19:34 +02:00
2012-08-01 03:33:30 +02:00
INSTALLDIR="$(dirname "$(dirname "$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")")" # Get main bash script directory's parent
2012-08-18 01:56:08 +02:00
if [ $# == 1 ] && ([ "$1" == '-l' ] || [ "$1" == '--list' ]); then
2012-08-01 03:33:30 +02:00
perl "$0.pl" "$INSTALLDIR" | cut -d @ -f 1 | uniq
2012-08-01 00:19:34 +02:00
else
2012-08-01 03:33:30 +02:00
_ponies="$(perl "$0.pl" "$INSTALLDIR")"
2012-08-01 00:19:34 +02:00
ponies=()
2012-08-18 01:56:08 +02:00
if (( $# > 0 )); then
2012-08-01 03:33:30 +02:00
p=()
2012-08-01 00:19:34 +02:00
for arg in "$@"; do
2012-08-18 01:56:08 +02:00
p+="$(echo "$_ponies" | grep "^$arg@") "
2012-08-01 00:19:34 +02:00
done
_ponies=$p
fi
2012-08-18 01:56:08 +02:00
ponies=( $_ponies )
2012-08-01 00:19:34 +02:00
2012-08-18 01:56:08 +02:00
if (( ${#ponies[@]} == 0 )); then
2012-08-01 00:19:34 +02:00
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)"
2012-08-01 03:33:30 +02:00
q="$(cat "$INSTALLDIR/share/ponysay/quotes/$f")"
2012-08-01 00:19:34 +02:00
echo "-f" $p $q
fi
fi