From c36d38613631953ff429470c179486057aa27320 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Nov 2026 17:16:17 +0100 Subject: Update AoC script --- scripts/aoc | 42 ++++++++++++++++++++++++++++++------------ 1 file 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 @@ # Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. # usage: aoc [yyyy nn] +# Must be run from inside tmux. # If yyyy (year) and nn (day, with leading zero if single digit) are not # specified, the current year and day are used. -editor="vi a.py" -basedir="$HOME/src/aoc" +if [ -z "$TMUX" ]; then + echo "Not in a tmux session!" + exit 1 +elif [ -z "$AOC_SESSION_COOKIE" ]; then + echo "Session cookie not found, must be in AOC_SESSION_COOKIE" + exit 1 +fi + +editor="vi" +file="a.cpp" +basedir="/tmp/$HOME/src/aoc" lynx_cookie_file="$(mktemp)" clibrowser="lynx -cookie_file=$lynx_cookie_file" @@ -16,37 +26,45 @@ year="${1:-$(date +'%Y')}" day="${2:-$(date +'%d')}" daynozero="$(echo "$day" | sed 's/^0//')" -cd "$basedir/$year/$day" +editpath="$basedir/$year/$day/$file" +inputs="$basedir/$year/inputs" + +mkdir -p "$basedir/$year/$day" +mkdir -p "$inputs" + +cd "$basedir/$year" # Download the puzzle input and save it to input.txt if [ ! -e input.txt ]; then url="https://adventofcode.com/$year/day/$daynozero/input" - curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt + curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o "$inputs/$day" fi # Download the problem statement page and split out the code blocks url="https://adventofcode.com/$year/day/$daynozero" curl "$url" | sed -n '/
/,/<\/code><\/pre>/ p' | (\
 	i=1
-	rm -f "code-$i.txt"
+	file="$day/code-$i.txt"
+	rm -f "$file"
 	IFS=''
 	while read -r line; do
 		if [ "$line" = "
" ]; then i=$((i + 1)) - rm -f "code-$i.txt" + rm -f "$file" else - echo "$line" | sed 's/<.*>//g' >> "code-$i.txt" + echo "$line" | sed 's/<.*>//g' >> "$file" fi done ) -# Open a tmux session with lynx in its own windows, and an editor and a -# terminal in split view. +# Open lynx in its own windows, and an editor and a terminal in split view. printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" -tmux new-session \; \ + +tmux \ + send-keys cd "$basedir/$year" C-m \; \ send-keys "$editor" C-m \; \ - split-window -h \; \ + split-window -h -c "$basedir/$year" \; \ select-pane -t 0 \; \ - new-window \; \ + new-window -c "$basedir/$year" \; \ send-keys "$clibrowser $url" C-m \; -- cgit v1.3