From 3b21e702c44d8f721e9ced997c417481f2c273ca Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 29 Nov 2025 13:44:34 +0100 Subject: Improved aoc script (was aocd) --- Makefile | 2 +- aoc | 35 +++++++++++++++++++++++++++++++++++ aocd | 13 ------------- 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100755 aoc delete mode 100755 aocd diff --git a/Makefile b/Makefile index f97e502..af98d4b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PREFIX = /usr/local SCRIPTS = 2fa \ - aocd \ + aoc \ battery-checknow \ battery-status \ clip \ diff --git a/aoc b/aoc new file mode 100755 index 0000000..56da404 --- /dev/null +++ b/aoc @@ -0,0 +1,35 @@ +#!/bin/sh + +# Set up a working environment for Advent of Code (https://adventofcode.com/). +# Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. + +# usage: aoc [yyyy nn] +# 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" +lynx_cookie_file="$(mktemp)" +clibrowser="lynx -cookie_file=$lynx_cookie_file" + +year="${1:-$(date +'%Y')}" +day="${2:-$(date +'%d')}" +daynozero="$(echo "$day" | sed 's/^0//')" + +cd "$basedir/$year/$day" + +# Download the puzzle input and save it to input.txt +url="https://adventofcode.com/$year/day/$daynozero/input" +curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt + +# Open a tmux session with 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" +url="https://adventofcode.com/$year/day/$daynozero" +tmux new-session \; \ + send-keys "$editor" C-m \; \ + split-window -h \; \ + select-pane -t 0 \; \ + new-window \; \ + send-keys "$clibrowser $url" C-m \; diff --git a/aocd b/aocd deleted file mode 100755 index cab4060..0000000 --- a/aocd +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# Download input from the Advent of Code website (https://adventofcode.com/). -# Requires setting an AOC_SESSION_COOKIE variable with a valid session cookie. - -# usage: aocd [year n] -# If year and n are not specified, the current year and day are used. - -YEAR="${1:-$(date +'%Y')}" -DAY="${2:-$(date +'%d' | sed 's/^0//')}" -URL="https://adventofcode.com/$YEAR/day/$DAY/input" - -curl "$URL" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt -- cgit v1.3