-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc
executable file
·73 lines (72 loc) · 1.79 KB
/
aoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
MYDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
usage() {
echo "Usage: $0 [-y <2016-Current year>] [-d <1-25>] [-p <1|2>]" 1>&2
exit 1
}
while getopts ":y:d:p:" o; do
case "${o}" in
y)
y=${OPTARG}
((y >= 2016)) || usage
YEAR=${y}
;;
d)
d=${OPTARG}
((d >= 1 && d <= 25)) || usage
DAY=${d}
;;
p)
p=${OPTARG}
((p == 1 || p == 2)) || usage
PART=${p}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
USE_CODE=go
MYEDITOR=goland
if [ -z "$YEAR" ]; then
YEAR=$(TZ=America/New_York date +%Y)
fi
if [ -z "$DAY" ]; then
DAY=$(TZ=America/New_York date +%d)
fi
if [ -z "$PART" ]; then
PART=1
fi
export AOC_SESSION=`cat ~/.aocdlconfig|jq -r '.["session-cookie"]'`
cd $MYDIR
if [ ! -e utils/aoc ]; then
cd utils
go build -o aoc ./cmd/aoc/main.go
cd ..
fi
./utils/aoc download -y $YEAR -d $DAY -p $PART
if [ $DAY -lt 10 ];then
DAY=`printf "%02d" $DAY`
fi
cd "$MYDIR/$YEAR/$DAY" || exit 1
if [ "$USE_CODE" == "py" ]; then
if [ ! -e part1.py ]; then
cp -R ../template/*.py ./
fi
elif [ "$USE_CODE" == "go" ]; then
if [ ! -e part1.go ]; then
go mod init "github.com/lazyguru/AdventOfCode/$YEAR/$DAY"
cp -R ../template/*.go ./
fi
fi
cp -R ../template/.gitignore ./
if [ "$MYEDITOR" == "nvim" ]; then
tmux new -d -s "aoc$YEAR$DAY" -x "$(tput cols)" -y "$(tput lines)" "nvim input.txt"
tmux split-window -t "aoc${YEAR}${DAY}" -h -p 80
tmux split-window -t "aoc${YEAR}${DAY}" -bp 70 nvim -p puzzle.md part${PART}.${USE_CODE} part${PART}_test.${USE_CODE}
tmux attach -t "aoc${YEAR}${DAY}"
else
$MYEDITOR .
fi
cd -