diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-11-29 13:44:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-11-29 13:44:34 +0100 |
| commit | 3b21e702c44d8f721e9ced997c417481f2c273ca (patch) | |
| tree | 7423e230e1e9715e469b5a9a53259d74eb081bee | |
| parent | 3fe83c0f2f7e6e3d87ede77607cca5922fa02a60 (diff) | |
| download | scripts-3b21e702c44d8f721e9ced997c417481f2c273ca.tar.gz scripts-3b21e702c44d8f721e9ced997c417481f2c273ca.zip | |
Improved aoc script (was aocd)
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rwxr-xr-x | aoc | 35 | ||||
| -rwxr-xr-x | aocd | 13 |
3 files changed, 36 insertions, 14 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | PREFIX = /usr/local | 1 | PREFIX = /usr/local |
| 2 | 2 | ||
| 3 | SCRIPTS = 2fa \ | 3 | SCRIPTS = 2fa \ |
| 4 | aocd \ | 4 | aoc \ |
| 5 | battery-checknow \ | 5 | battery-checknow \ |
| 6 | battery-status \ | 6 | battery-status \ |
| 7 | clip \ | 7 | clip \ |
| @@ -0,0 +1,35 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Set up a working environment for Advent of Code (https://adventofcode.com/). | ||
| 4 | # Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. | ||
| 5 | |||
| 6 | # usage: aoc [yyyy nn] | ||
| 7 | # If yyyy (year) and nn (day, with leading zero if single digit) are not | ||
| 8 | # specified, the current year and day are used. | ||
| 9 | |||
| 10 | editor="vi a.py" | ||
| 11 | basedir="$HOME/src/aoc" | ||
| 12 | lynx_cookie_file="$(mktemp)" | ||
| 13 | clibrowser="lynx -cookie_file=$lynx_cookie_file" | ||
| 14 | |||
| 15 | year="${1:-$(date +'%Y')}" | ||
| 16 | day="${2:-$(date +'%d')}" | ||
| 17 | daynozero="$(echo "$day" | sed 's/^0//')" | ||
| 18 | |||
| 19 | cd "$basedir/$year/$day" | ||
| 20 | |||
| 21 | # Download the puzzle input and save it to input.txt | ||
| 22 | url="https://adventofcode.com/$year/day/$daynozero/input" | ||
| 23 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
| 24 | |||
| 25 | # Open a tmux session with lynx in its own windows, and an editor and a | ||
| 26 | # terminal in split view. | ||
| 27 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ | ||
| 28 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" | ||
| 29 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 30 | tmux new-session \; \ | ||
| 31 | send-keys "$editor" C-m \; \ | ||
| 32 | split-window -h \; \ | ||
| 33 | select-pane -t 0 \; \ | ||
| 34 | new-window \; \ | ||
| 35 | send-keys "$clibrowser $url" C-m \; | ||
| @@ -1,13 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Download input from the Advent of Code website (https://adventofcode.com/). | ||
| 4 | # Requires setting an AOC_SESSION_COOKIE variable with a valid session cookie. | ||
| 5 | |||
| 6 | # usage: aocd [year n] | ||
| 7 | # If year and n are not specified, the current year and day are used. | ||
| 8 | |||
| 9 | YEAR="${1:-$(date +'%Y')}" | ||
| 10 | DAY="${2:-$(date +'%d' | sed 's/^0//')}" | ||
| 11 | URL="https://adventofcode.com/$YEAR/day/$DAY/input" | ||
| 12 | |||
| 13 | curl "$URL" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
