advent_of_code/scripts/mkday
2023-12-05 11:52:53 +01:00

40 lines
650 B
Bash
Executable File

#!/bin/bash
while getopts y:l:d: flag
do
case "${flag}" in
y) year=${OPTARG};;
l) language=${OPTARG};;
d) day=${OPTARG};;
esac
done
if [[ ! $year || ! $language || ! $day ]]
then
echo "Invalid usage! Required flags are -y, -l and -d";
echo "Bye...";
exit 1;
fi
case $language in
"ts") lang="typescript";;
*) lang="unknown";;
esac
cd $year
mkdir -p $lang/day$day
cp ../templates/$lang/* ./$lang/day$day
cd ./$lang/day$day
for f in d*.txt
do
if [[ "$f" =~ ^(d)XX(p[0-9]\.)txt$ ]]; then
mv "$f" "${BASH_REMATCH[1]}${day}${BASH_REMATCH[2]}ts"
fi
done
mv "index.txt" "index.ts"