ponysay/pq4ps

42 lines
920 B
Text
Raw Normal View History

2012-08-01 00:19:34 +02:00
#!/bin/bash
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-01 00:19:34 +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-01 03:33:30 +02:00
if (( $# > 1 )); then
p=()
2012-08-01 00:19:34 +02:00
for arg in "$@"; do
2012-08-01 03:33:30 +02:00
p+=( $(echo "$_ponies" | grep "^$arg@") )
2012-08-01 00:19:34 +02:00
done
_ponies=$p
fi
for _pony in $_ponies; do
ponies+=( $_pony )
done
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)"
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