From e2fdc6aee4baf5939266a68938c359bf635f2d05 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 1 Dec 2021 10:22:00 -0500 Subject: [PATCH] use current date(1) if $1 is missing --- aoc2021/getday.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/aoc2021/getday.sh b/aoc2021/getday.sh index eb7faa0..e9d8d6a 100644 --- a/aoc2021/getday.sh +++ b/aoc2021/getday.sh @@ -5,9 +5,18 @@ if [ -z "$session" ]; then printf "missing session cookie\n" fi - -curl -s https://adventofcode.com/2021/day/"$1"/input \ - --cookie "session=$session" \ - -o "$(printf "input/day%02d.in" "$1")" -sed "s/XX/$1/g" DayXX.cs.txt > "$(printf "Day%02d.cs" "$1")" +if [ -z "$1" ]; then + day=$(date +"%e" | xargs) +else + day="$1" +fi + +curl -s https://adventofcode.com/2021/day/"$day"/input \ + --cookie "session=$session" \ + -o "$(printf "input/day%02d.in" "$day")" + +class=$(printf "Day%02d.cs" "$day") +if [ ! -f "$class" ]; then + sed "s/XX/$1/g" DayXX.cs.txt > "$class" +fi