-
Notifications
You must be signed in to change notification settings - Fork 1
/
start
executable file
·82 lines (68 loc) · 2.02 KB
/
start
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
DAY=$1
if [[ $DAY -lt 10 ]]; then
DIR=day0$1
else
DIR=day$1
fi
YEAR=${2:-2024}
cd ~/aoc
mkdir -p "$YEAR/$DIR"
cd "$YEAR/$DIR"
fetch_examples() {
echo "Fetching examples..."
local INDEX=1
curl -Ss "https://adventofcode.com/$YEAR/day/$DAY" \
-H "User-Agent: https://aoc.cgs.dev friendly bash script by [email protected]" \
-H "cookie: session=$(cat ~/.aoc)" > puzzle.html
while IFS= read -r line; do
printf "\n\n\n%s" "$line" &> /dev/stderr
echo "$line" | jq -r '.example' > sample${INDEX}.txt
SOLUTION="$(echo "$line" | jq -r '.solution')"
printf "%s" "$SOLUTION" > solution${INDEX}.txt
((INDEX++))
done < <(cat puzzle.html | pup 'article' | ~/aoc/misc/claude | tee /dev/stderr | jq -r '.content[0].text' | jq -rc '.[]')
}
start_part_2() {
SANITY="$(cat p2.sh | sha256sum | cut -d' ' -f1)"
if [[ "$SANITY" == "eebb73afcb24017e3fb49b70786a41e0c2e01fbef4230ae0b75294e93d265205" ]]; then
echo "Basing p2 on p1 because p2 was blank"
cp p1.sh p2.sh
fi
fetch_examples
tmux next-window
tmux select-pane -t bottom-right
tmux send-keys C-c
tmux send-keys "~/aoc/test-runner $YEAR $DAY 2" Enter
tmux select-pane -t top-right
tmux send-keys C-c
tmux send-keys C-c
tmux send-keys C-p Enter
tmux select-pane -t left
}
touch p1.sh p2.sh
chmod +x p1.sh p2.sh
cat <<-EOF | tee p1.sh > p2.sh
#!/bin/bash
FILE="\$1"
cat "\$FILE"
EOF
if [[ ! -f "input.txt" ]]; then
curl -Ss "https://adventofcode.com/$YEAR/day/$DAY/input" \
-H "User-Agent: https://aoc.cgs.dev friendly bash script by [email protected]" \
-H "cookie: session=$(cat ~/.aoc)" > input.txt
fi
fetch_examples
tmux new-window
tmux send-keys "cd ~/aoc/$YEAR/$DIR; vim p1.sh p2.sh" Enter
tmux split-window -h
tmux send-keys "cd ~/aoc/$YEAR/$DIR" Enter
tmux send-keys "~/aoc/misc/browser $YEAR $DAY" Enter
tmux split-window -v
tmux send-keys "cd ~/aoc/$YEAR/$DIR" Enter
tmux send-keys "~/aoc/test-runner $YEAR $DAY 1" Enter
echo
echo
echo ===========================
read -n 1 -s -r -p "Press any key to begin part 2\n"
start_part_2