83 lines
2.3 KiB
Bash
Executable File
83 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Copyright (C) 2020 Gary Kim <gary@garykim.dev>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
set -euf -o pipefail
|
|
|
|
# This line will only work in scripts and not sourced bash scripts.
|
|
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
|
|
|
|
GREETINGS=("I hope you have a great day!" "Have another great year!" "Thank you for your friendship with me!" "You're now one year wiser! I expect even better things from you!")
|
|
|
|
number () {
|
|
if [ $(( ($1 / 10) % 10 )) -eq 1 ]; then
|
|
echo -en "$1th"
|
|
exit 0
|
|
fi
|
|
if [ $(( $1 % 10 )) -eq 1 ]; then
|
|
echo -en "$1st"
|
|
exit 0
|
|
fi
|
|
if [ $(( $1 % 10 )) -eq 2 ]; then
|
|
echo -en "$1nd"
|
|
exit 0
|
|
fi
|
|
if [ $(( $1 % 10 )) -eq 3 ]; then
|
|
echo -en "$1rd"
|
|
exit 0
|
|
fi
|
|
echo -en "$1th"
|
|
exit 0
|
|
}
|
|
|
|
random_greeting () {
|
|
echo ${GREETINGS[$(( RANDOM % 4 ))]}
|
|
}
|
|
|
|
if [ "$#" -lt 1 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
|
BASENAME=$(basename "$0")
|
|
echo "Usage: $BASENAME <BIRTHDAY_PERSON_NAME> <BIRTHDAY_PERSON_AGE> <CARD_SENDER_NAME>"
|
|
echo ""
|
|
echo "$BASENAME is a script for generating birthday cards easily on the command line."
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $BASENAME \"Birthday Child\" 13 \"Dad\""
|
|
echo " $BASENAME \"Best Friend\" 25 \"Your Pal\""
|
|
exit 0
|
|
fi
|
|
|
|
# Basic sanity check
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "Incorrect number of arguments"
|
|
exit 1
|
|
fi
|
|
|
|
BIRTHDAY_NAME="$1"
|
|
BIRTHDAY_AGE="$2"
|
|
SENDER_NAME="$3"
|
|
|
|
MESSAGE="Dear $BIRTHDAY_NAME,\n\n"
|
|
|
|
i=0
|
|
while [ $i -lt $BIRTHDAY_AGE ]; do
|
|
MESSAGE+="Happy "
|
|
i=$(( $i + 1 ))
|
|
done
|
|
|
|
MESSAGE+="$( number $BIRTHDAY_AGE ) Birthday!\n\n$( random_greeting )\n\n$SENDER_NAME"
|
|
|
|
echo -e "$MESSAGE"
|