ponysay/extras/fortune-mod-mlp/name-pony.sh
Mattias Andrée 9405806e7c derp: forgot to print the hardcoded names
Signed-off-by: Mattias Andrée <maandree@operamail.com>
2013-12-10 16:14:45 +01:00

33 lines
880 B
Bash
Executable file

#!/bin/sh
file="$1/$2.pony"
pony="$2"
name=""
case "${pony}" in # Exceptions not supported by the name extraction below
(carrot) name="Carrot";;
(chrysalis) name="Chrysalis";;
(lemonhearts) name="Lemon Hearts";;
(lily) name="Lily Valley";;
(snowflake) name="Snowflake";;
(twinkleshine) name="Twinkleshine";;
(rumble) name="Rumble";;
esac
if [ -n "${name}" ]; then
echo "${name}"
exit 0
fi
name="$(cat "$file" | grep '^NAME: ' | sed -e 's/^NAME: //g')"
name="$(echo $(echo "$name" | grep -o '[^,(]*' | head -n 1))"
full_name="$(cat "$file" | grep '^OTHER NAMES: ' | sed -e 's/^OTHER NAMES: /, /g')"
full_name="$(echo $(echo "$full_name" | grep -o ', [^,(]* (official, full name[a-z]*)' | grep -o ' [^,(]*' | head -n 1))"
if test -n "${full_name}"; then
echo "${full_name}"
else
echo "${name}"
fi