From 48f78825b87c54070a5e277f035463634ed8e74b Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 6 Dec 2021 15:39:40 +0100 Subject: [PATCH] aoc-get: default to current day in december --- aoc-get/aoc-get | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/aoc-get/aoc-get b/aoc-get/aoc-get index a6248f0..dbe975b 100755 --- a/aoc-get/aoc-get +++ b/aoc-get/aoc-get @@ -15,25 +15,37 @@ set --append options (fish_opt --short y --long year --required-val)"!_validate_ argparse $options -- $argv -set --query _flag_year; or set --local _flag_year (date +%Y) - if set --query _flag_help usage exit 0 end -if not set --query _flag_day - echo "Please provide a day to fetch" - exit 1 +# automatically set day if we're in December, otherwise require a value +set --local flag_day +if set --query _flag_day + set flag_day _flag_day +else + set --local month (date +%-m) + if [ $month -eq 12 ] + set flag_day (date +%-d) + else + echo "Please provide a day to fetch" + exit 1 + end end +set --query _flag_year; or set --local _flag_year (date +%Y) + if not set --query AOC_SESSION echo "Please provide a session cookie via the AOC_SESSION environment variable" exit 1 end -set --local padded_day (string pad --width 2 --char 0 $_flag_day) +set --local padded_day (string pad --width 2 --char 0 {$flag_day}) +set --local outpath aoc{$_flag_year}/input/day{$padded_day}.txt -curl https://adventofcode.com/{$_flag_year}/day/{$_flag_day}/input \ +echo "Saving input to" {$outpath} "..." + +curl https://adventofcode.com/{$_flag_year}/day/{$flag_day}/input \ --cookie "session="{$AOC_SESSION} \ - --output aoc{$_flag_year}/input/day{$padded_day}.txt + --output {$outpath}