Skip to content

Commit 2661046

Browse files
authored
Support $AOC_LANG
1 parent c079436 commit 2661046

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ My solutions to puzzles at [adventofcode.com](https://adventofcode.com/). Also c
2626
"-_/}__ `}-'_/`-, /`-,( _,,.{-,_(__,,,.(
2727
[(_.-'`--,__ ____/`-,.(,-`}-'_,>___\/`-, >|`---\
2828
[(__\___\ _`-(--...(..-'_`./`-,/(--,,.( // / >
29-
|_______/-' >`---\ / ( `{ >`---\
29+
|_______/-' >`---\ / ( `{ >`---\
3030
__|___|__) / \ / \ /`--/< / \ /|
3131
/ \/ \
3232
```
@@ -87,6 +87,12 @@ bin/solve_day.sh 19/5 # 2019 day 5
8787
bin/solve_day.sh -l py # Solve with language, here Python
8888
```
8989

90+
> [!TIP]
91+
> The default language could be set with an envvar, e.g. with dotenv in a `.env` file which is also read by `bin/solve_day.sh`:
92+
. ```shell
93+
. echo "AOC_LANG=py" >> .env
94+
. ```
95+
9096

9197
## Session Cookie Expired?
9298
Update:

bin/solve_day.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main():
4343
line = line.rstrip("\n")
4444
4545
if __name__ == '__main__':
46-
main()
46+
main()
4747
TEMPLATE
4848
)
4949

@@ -68,7 +68,7 @@ enter_day() {
6868
# Load .env if it exist.
6969
# Ref: https://www.cicoria.com/loading-env-dotenv-using-bash-or-zsh/
7070
load_dotenv() {
71-
test -f .env || return
71+
test -f .env || return
7272
set -o allexport; source .env; set +o allexport
7373
}
7474

@@ -90,8 +90,12 @@ fetch_input() {
9090
}
9191

9292

93+
. $SCRIPT_DIR/lib.sh
94+
cd_git_root
95+
load_dotenv
9396

94-
arg_lang="rb"
97+
# Arg parsing
98+
arg_lang="${AOC_LANG:-rb}" # Can be set in .env or in shell env.
9599
while getopts ":l:h?" opt; do
96100
case "$opt" in
97101
l) arg_lang="$OPTARG";;
@@ -101,7 +105,6 @@ while getopts ":l:h?" opt; do
101105
done
102106
shift $(($OPTIND - 1))
103107

104-
105108
year=$(date +%Y)
106109
day=$(date +%d)
107110
if [ $# -eq 1 ]; then
@@ -113,14 +116,10 @@ if [ $# -eq 1 ]; then
113116
test ${#day} -eq 2 || day="0$day"
114117
fi
115118

119+
# File setup
116120
files=(README.txt input input1.0 output1.0)
117121
files+=("part1.${arg_lang}")
118122
files+=("part2.${arg_lang}")
119-
120-
121-
. $SCRIPT_DIR/lib.sh
122-
cd_git_root
123-
load_dotenv
124123
enter_day $year $day $arg_lang files
125124
fetch_input $year $(echo $day | bc)
126125

@@ -142,4 +141,4 @@ cd_git_root
142141
bin/stats.sh
143142

144143
git status
145-
printf "\n\ngit add %s && git commit -m \"Add %s ${arg_lang}\" && git fetch && git rebase && git push && tig\n" "$path" "$path"
144+
printf "\n\ngit add %s && git commit -m \"Add %s ${arg_lang}\" && git fetch && git rebase && git push && tig\n" "$path" "$path"

0 commit comments

Comments
 (0)