summaryrefslogtreecommitdiff
path: root/scripts/aoc
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-11-26 17:16:17 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2026-11-26 17:16:17 +0100
commitc36d38613631953ff429470c179486057aa27320 (patch)
tree066ec1b22633a8ca3dc6abdf7e1f6702022960d3 /scripts/aoc
parent6e5673e23844d8c674992dfa79702ce15703b165 (diff)
downloadconfig-c36d38613631953ff429470c179486057aa27320.tar.gz
config-c36d38613631953ff429470c179486057aa27320.zip
Update AoC scriptHEADmaster
Diffstat (limited to '')
-rwxr-xr-xscripts/aoc42
1 files changed, 30 insertions, 12 deletions
diff --git a/scripts/aoc b/scripts/aoc
index 40f94ed..e25131e 100755
--- a/scripts/aoc
+++ b/scripts/aoc
@@ -4,11 +4,21 @@
4# Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. 4# Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie.
5 5
6# usage: aoc [yyyy nn] 6# usage: aoc [yyyy nn]
7# Must be run from inside tmux.
7# If yyyy (year) and nn (day, with leading zero if single digit) are not 8# If yyyy (year) and nn (day, with leading zero if single digit) are not
8# specified, the current year and day are used. 9# specified, the current year and day are used.
9 10
10editor="vi a.py" 11if [ -z "$TMUX" ]; then
11basedir="$HOME/src/aoc" 12 echo "Not in a tmux session!"
13 exit 1
14elif [ -z "$AOC_SESSION_COOKIE" ]; then
15 echo "Session cookie not found, must be in AOC_SESSION_COOKIE"
16 exit 1
17fi
18
19editor="vi"
20file="a.cpp"
21basedir="/tmp/$HOME/src/aoc"
12lynx_cookie_file="$(mktemp)" 22lynx_cookie_file="$(mktemp)"
13clibrowser="lynx -cookie_file=$lynx_cookie_file" 23clibrowser="lynx -cookie_file=$lynx_cookie_file"
14 24
@@ -16,37 +26,45 @@ year="${1:-$(date +'%Y')}"
16day="${2:-$(date +'%d')}" 26day="${2:-$(date +'%d')}"
17daynozero="$(echo "$day" | sed 's/^0//')" 27daynozero="$(echo "$day" | sed 's/^0//')"
18 28
19cd "$basedir/$year/$day" 29editpath="$basedir/$year/$day/$file"
30inputs="$basedir/$year/inputs"
31
32mkdir -p "$basedir/$year/$day"
33mkdir -p "$inputs"
34
35cd "$basedir/$year"
20 36
21# Download the puzzle input and save it to input.txt 37# Download the puzzle input and save it to input.txt
22if [ ! -e input.txt ]; then 38if [ ! -e input.txt ]; then
23 url="https://adventofcode.com/$year/day/$daynozero/input" 39 url="https://adventofcode.com/$year/day/$daynozero/input"
24 curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt 40 curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o "$inputs/$day"
25fi 41fi
26 42
27# Download the problem statement page and split out the code blocks 43# Download the problem statement page and split out the code blocks
28url="https://adventofcode.com/$year/day/$daynozero" 44url="https://adventofcode.com/$year/day/$daynozero"
29curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\ 45curl "$url" | sed -n '/<pre><code>/,/<\/code><\/pre>/ p' | (\
30 i=1 46 i=1
31 rm -f "code-$i.txt" 47 file="$day/code-$i.txt"
48 rm -f "$file"
32 IFS='' 49 IFS=''
33 while read -r line; do 50 while read -r line; do
34 if [ "$line" = "</code></pre>" ]; then 51 if [ "$line" = "</code></pre>" ]; then
35 i=$((i + 1)) 52 i=$((i + 1))
36 rm -f "code-$i.txt" 53 rm -f "$file"
37 else 54 else
38 echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" 55 echo "$line" | sed 's/<.*>//g' >> "$file"
39 fi 56 fi
40 done 57 done
41) 58)
42 59
43# Open a tmux session with lynx in its own windows, and an editor and a 60# Open lynx in its own windows, and an editor and a terminal in split view.
44# terminal in split view.
45printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ 61printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \
46 "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" 62 "$AOC_SESSION_COOKIE" > "$lynx_cookie_file"
47tmux new-session \; \ 63
64tmux \
65 send-keys cd "$basedir/$year" C-m \; \
48 send-keys "$editor" C-m \; \ 66 send-keys "$editor" C-m \; \
49 split-window -h \; \ 67 split-window -h -c "$basedir/$year" \; \
50 select-pane -t 0 \; \ 68 select-pane -t 0 \; \
51 new-window \; \ 69 new-window -c "$basedir/$year" \; \
52 send-keys "$clibrowser $url" C-m \; 70 send-keys "$clibrowser $url" C-m \;

Generated with cgit - Back to sebastiano.tronto.net