aboutsummaryrefslogtreecommitdiff
path: root/pq4ps
diff options
context:
space:
mode:
Diffstat (limited to 'pq4ps')
-rwxr-xr-xpq4ps39
1 files changed, 39 insertions, 0 deletions
diff --git a/pq4ps b/pq4ps
new file mode 100755
index 0000000..433f062
--- /dev/null
+++ b/pq4ps
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+if [[ $# == 1 ]] && [[ "$1" == '-l' || "$1" == '--list' ]]; then
+ perl $0.pl | cut -d @ -f 1 | uniq
+else
+ _ponies="$(perl $0.pl)"
+ ponies=()
+
+ if [[ ! $# == 0 ]]; then
+ p=""
+ for arg in "$@"; do
+ p=$p$(echo "$_ponies" | grep "^$arg@")" "
+ 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)"
+ q="$(cat "/usr/share/ponysay/quotes/$f")"
+
+ echo "-f" $p $q
+ fi
+fi