aoc/gen.sh

39 lines
762 B
Bash
Executable file

#!/usr/bin/env bash
Y="$1"; shift
if [ -z "$Y" ]; then
Y="$(date +%Y)"
fi
fday="$1"; shift
tday="$1"; shift
if [ -z "$fday" ]; then
fday=1
tday=25
fi
if [ -z "$tday" ]; then
tday="${fday}"
fi
days=($(seq $fday $tday))
if ! grep -q "Y${Y}" src/AoC/Year.hs; then
sed -i -e "s/\(\(\s\+\)= Y0000\)/\1\n\2| Y${Y}/" src/AoC/Year.hs
fi
mkdir -p "src/AoC/Y${Y}"
if ! test -f "src/AoC/Y${Y}.hs"; then
sed -e "s/Y0000/Y${Y}/g" template/Y0000.hs > "src/AoC/Y${Y}.hs"
fi
for d in "${days[@]}"; do
d=$(printf "%02d" "$d")
mkdir -p "data/Y${Y}/D${d}"
touch "data/Y${Y}/D${d}/riddle"
touch "data/Y${Y}/D${d}/result"
if ! test -f "src/AoC/Y${Y}/D${d}.hs"; then
sed -e "s/Y0000/Y${Y}/g" -e "s/D00/D${d}/g" template/D00.hs > "src/AoC/Y${Y}/D${d}.hs"
fi
done