aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2012-02-26 20:30:25 +0100
committerJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2012-02-26 20:30:48 +0100
commit38f8c51bba0e63e47bbde6c4a3043a6bdfa22250 (patch)
tree4d01ee786034cbf7b5de07e37efe8894ad35344f
parent7039eab51790628a2c378668ac04bf69a028740e (diff)
downloadponysay-38f8c51bba0e63e47bbde6c4a3043a6bdfa22250.tar.gz
ponysay-38f8c51bba0e63e47bbde6c4a3043a6bdfa22250.tar.bz2
ponysay-38f8c51bba0e63e47bbde6c4a3043a6bdfa22250.zip
Unbreak providing the message via argument. Whoops
-rwxr-xr-xponysay24
1 files changed, 19 insertions, 5 deletions
diff --git a/ponysay b/ponysay
index ac04ba6..42db27a 100755
--- a/ponysay
+++ b/ponysay
@@ -17,7 +17,9 @@ usage() {
version
echo
echo "Usage:"
- echo "${0##*/} [options]"
+ echo "${0##*/} [options] [message]"
+ echo
+ echo "If [message] is not provided, reads the message from STDIN"
echo
echo "Options:"
echo " -v Show version and exit"
@@ -26,6 +28,10 @@ usage() {
echo " -W[column] The screen column where the message should be wrapped"
}
+say() {
+ exec "$cmd" -f "$pony" "${wrap:+-W$wrap}"
+}
+
while getopts f:W:hv OPT
do
case ${OPT} in
@@ -36,23 +42,31 @@ do
\?) usage >&2; exit 1 ;;
esac
done
+shift $((OPTIND - 1))
-# Pony not a file? Search for it
if [[ ! -f $pony ]]; then
+ # Pony not a file? Search for it
+
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
+ 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" "${wrap:+-W$wrap}"
+if [[ -n "$*" ]]; then
+ # Handle a message given via arguments
+ say <<<"$*"
+else
+ say
+fi