diff options
author | Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> | 2012-02-26 20:01:22 +0100 |
---|---|---|
committer | Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> | 2012-02-26 20:06:19 +0100 |
commit | 9e222c3d09001413dac2fb8a659c6fc378caea0f (patch) | |
tree | 64454fd2f39cf6122237149af1b8e82c54d6ce5d | |
parent | 729ac65c7f3174e6b4119a696c14330c9b488e3a (diff) | |
download | ponysay-9e222c3d09001413dac2fb8a659c6fc378caea0f.tar.gz ponysay-9e222c3d09001413dac2fb8a659c6fc378caea0f.tar.bz2 ponysay-9e222c3d09001413dac2fb8a659c6fc378caea0f.zip |
Add usage and version functions
-rwxr-xr-x | ponysay | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -1,23 +1,36 @@ #!/usr/bin/env bash -# Ponies use UTF-8 drawing characters. Prevent a Perl warning. -export PERL_UNICODE=S - +version=0.4 SYSTEMPONIES=/usr/share/ponies HOMEPONIES="${HOME}/.ponies" +pony= cmd=cowsay [[ ${0} == *ponythink ]] && cmd=cowthink -pony= +version() { + echo "ponysay v$version" +} + +usage() { + version + echo + echo "Usage:" + echo "${0##*/} [options]" + echo + echo "Options:" + echo " -v Show version and exit" + echo " -h Show this help and exit" + echo " -f[name] Select a pony (Either a filename or a pony name)" +} while getopts f:hv OPT do case ${OPT} in - v) echo "ponysay v0.4" ; exit;; - h) echo "-v for version, -h for this, -f to specify a ponyfile. It'll choose a random ponyfile if no argument is given." ; exit;; + v) version; exit ;; + h) usage; exit ;; f) pony=$OPTARG ;; - \?) echo "DERP"; exit;; + \?) usage; exit 1 ;; esac done @@ -41,4 +54,7 @@ if [[ ! -f $pony ]]; then pony="${ponies[$RANDOM%${#ponies[@]}]}" fi +# Ponies use UTF-8 drawing characters. Prevent a Perl warning. +export PERL_UNICODE=S + exec "$cmd" -f "$pony" |