AdventOfCode2023/make_readme.sh

26 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2023-12-06 12:15:51 +01:00
#!/bin/bash
2023-12-09 11:53:29 +01:00
table="| Day | Language | Lines of code | Execuction time | Comment |\n"
2023-12-09 11:54:33 +01:00
table+="|:---:|:---:| ---:| ---: |--- |\n"
2023-12-13 16:29:26 +01:00
maxday=$(ls -d */ | sed -r 's|0*(.*)/|\1|g' | tail -1)
for day in $(seq -f "%02g" 1 $maxday); do
if [[ ! -d "$day" ]]; then
echo "Missing directory for day $day"
continue
fi
if [[ ! -f "$day/README.md" ]]; then
echo "Missing README for day $day"
continue
fi
2023-12-06 12:15:51 +01:00
# echo $day
2023-12-08 13:52:28 +01:00
lang=$(grep -E "Today's language:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
exectime=$(grep -E "Execution time:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
2023-12-09 11:53:29 +01:00
loc=$(grep -E "Lines of code:" $day/README.md | sed -r 's/.*\*\*(.+)\*\*.*/\1/')
2023-12-06 12:15:51 +01:00
comment=$(grep -E "<!-- .* -->" $day/README.md | head -1 | sed -r 's/.*<!-- *(.*) *-->.*/\1/')
2023-12-09 11:53:29 +01:00
table+="| [$day]($day) | $lang | $loc | $exectime | $comment |\n"
2023-12-06 12:15:51 +01:00
done
# remove table from readme
sed -i '/<!-- table begin -->/q' README.md
echo -e $table | column -t -s '|' -o '|' >> README.md
2023-12-09 11:53:29 +01:00
echo -e "\n Lines of code are without blank lines and comments" >> README.md