-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformegathread
More file actions
executable file
·39 lines (35 loc) · 1.13 KB
/
formegathread
File metadata and controls
executable file
·39 lines (35 loc) · 1.13 KB
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
#!/bin/zsh
# Copyright 2025 Trevor Stone
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# Starts a Solutions Megathread comment for r/adventofcode by indenting the
# code block, removing comments, and adding a header.
if (($# != 1)); then
print -u 2 "Usage: $0 day1/day1.xyz"
exit 1
fi
year=$(date +%Y)
solution=$1
outdir=${TMPDIR-/tmp}/aoc
mdfile=$outdir/${solution:t}.md
mkdir -p $outdir
ext=${solution:e}
typeset -A names
names=(awk AWK exs Elixir jl Julia jq jq kt Kotlin pl Perl ps PostScript py Python rb Ruby sql SQL zsh 'Z shell')
langname=${names[$ext]-${(C)ext}}
case $ext in
(lua) skip=(-e '/^\s*\(#|--\)/d') ;;
(go|jsonnet|kt) skip=(-e '/^\s*\/\//d') ;;
(ps) skip=(-e '/^\s*%/d' -e '/cob\.require/d') ;;
(sql) skip=(-e '/^\s*--/d') ;;
(*) skip=(-e '/^\s*#/d')
esac
code=$(sed -e '/^#!/d' $skip -e '/^$/d' $solution | pr -to 4)
echo "Writing $solution to $mdfile"
cat > $mdfile <<EOT
[LANGUAGE: $langname] ([on GitHub](https://github.com/flwyd/adventofcode/blob/main/$year/${solution:h:t}/${solution:t}))
Thoughts
$code
EOT