mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-26 06:07:59 +01:00
Add usage and version functions
This commit is contained in:
parent
729ac65c7f
commit
9e222c3d09
1 changed files with 23 additions and 7 deletions
30
ponysay
30
ponysay
|
@ -1,23 +1,36 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
version=0.4
|
||||||
export PERL_UNICODE=S
|
|
||||||
|
|
||||||
SYSTEMPONIES=/usr/share/ponies
|
SYSTEMPONIES=/usr/share/ponies
|
||||||
HOMEPONIES="${HOME}/.ponies"
|
HOMEPONIES="${HOME}/.ponies"
|
||||||
|
pony=
|
||||||
|
|
||||||
cmd=cowsay
|
cmd=cowsay
|
||||||
[[ ${0} == *ponythink ]] && cmd=cowthink
|
[[ ${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
|
while getopts f:hv OPT
|
||||||
do
|
do
|
||||||
case ${OPT} in
|
case ${OPT} in
|
||||||
v) echo "ponysay v0.4" ; exit;;
|
v) version; 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;;
|
h) usage; exit ;;
|
||||||
f) pony=$OPTARG ;;
|
f) pony=$OPTARG ;;
|
||||||
\?) echo "DERP"; exit;;
|
\?) usage; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -41,4 +54,7 @@ if [[ ! -f $pony ]]; then
|
||||||
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
pony="${ponies[$RANDOM%${#ponies[@]}]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ponies use UTF-8 drawing characters. Prevent a Perl warning.
|
||||||
|
export PERL_UNICODE=S
|
||||||
|
|
||||||
exec "$cmd" -f "$pony"
|
exec "$cmd" -f "$pony"
|
||||||
|
|
Loading…
Reference in a new issue