-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·33 lines (28 loc) · 1.04 KB
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Initializes a new year for the Advent of Code. Creates a very basic directory
# and file structure that can be customized for each individual day in the event.
#
# Arguments:
# The year to initialize. Defaults to current year.
YEAR="${1:-$(date +%Y)}"
DAYS=25
INTRO_FILE_NAME='introduction.md'
PUZZLE_FILE_NAME='puzzle.md'
SOLUTION_FILE_NAME='solution.py'
INPUT_FILE_NAME='input.txt'
TEST_FILE_NAME='test.txt'
if [ -d "$YEAR" ]; then
printf 'Directory for year %s already exists, cannot init.\n' "$YEAR"
exit 1
fi
# Create the year's directory and introduction file
mkdir "${YEAR}"
pushd "$YEAR" || { printf "Failed to navigate to directory: %s\n" "$YEAR"; exit 1; }
touch "$INTRO_FILE_NAME"
# Create a directory for each day with files to hold the puzzle description,
# the test input, the actual input, and the solution script.
for i in $(seq -f '%02g' $DAYS); do
mkdir "$i"
touch "$i"/{$PUZZLE_FILE_NAME,$SOLUTION_FILE_NAME,$INPUT_FILE_NAME,$TEST_FILE_NAME}
done
popd || { printf "Failed to leave directory: %s\n" "$YEAR"; exit 1; }