-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeDay.sh
executable file
·54 lines (43 loc) · 1.04 KB
/
makeDay.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Check is session key files exists
if [[ -f "session.txt" ]]
then
session=$(<session.txt)
else
read -p "Please enter you session key: " session
touch session.txt
echo ${session} > session.txt
fi
# Read user input
read -p "Which day is it? : " rawNumber
# Remove leading zeros
rawNumber=$((10#$rawNumber))
# Add leading zero from 1 to 9
if ((rawNumber >= 1 && rawNumber <= 9)); then
number=0${rawNumber}
else
number=${rawNumber}
fi
# Day folder name
day="day-${number}"
# Check that directory does not exist yet
if [[ -d ${day} ]]
then
echo "${day} already exists!"
code ${day}
exit 0
fi
# Create new Rust project
cargo new ${day} --vcs none
# Create input files
touch ${day}/input1.txt
touch ${day}/input2.txt
touch ${day}/official_input.txt
curl --cookie "session=${session}" https://adventofcode.com/2023/day/${rawNumber}/input > ${day}/official_input.txt
# Create main from template
rm ${day}/src/main.rs
cp template/template.rs ${day}/src/main.rs
# Test run the template
cd ${day}
cargo run
code .