File tree Expand file tree Collapse file tree 4 files changed +115
-0
lines changed
Expand file tree Collapse file tree 4 files changed +115
-0
lines changed Original file line number Diff line number Diff line change 1+ # editor detritus
2+ . * sw ?
3+ * ~
4+
5+ # Finder turds
6+ .DS_Store
Original file line number Diff line number Diff line change 1+ #!/usr/bin/awk -f
2+ ##
3+ ## markin - interpolate shell script into Markdown files
4+ ##
5+ ## Author: Kevin Ernst <ernstki -at- mail.uc.edu>
6+ ## Date: 12 March 2022
7+ ## Homepage: https://github.com/ernstki/markin
8+ ## License: MIT
9+ ##
10+ BEGIN { loop_max = 10 }
11+
12+ # <!-- {{{begin
13+ /^ * <!-- * {+ begin * / {
14+ c = LOOP_MAX
15+ i = 0
16+ print ; getline
17+
18+ # }}} -->
19+ while (! /^ * }+ * -- > * $/) {
20+ print
21+ cmd = "$SHELL -c '" $ 0 "'"
22+
23+ while (cmd | getline) {
24+ output[i ++ ] = $ 0
25+ }
26+
27+ close(cmd)
28+ # “…[W ]hen a file or pipe is opened for output, awk remembers the file
29+ # name or command associated with it, and subsequent writes to the same
30+ # file or command are appended to the previous writes. The file or pipe
31+ # stays open until awk exits.
32+ #
33+ # This implies that special steps are necessary in order to read the
34+ # same file again from the beginning, or to rerun a shell command
35+ # (rather than reading more output from the same command). The close()
36+ # function makes these things possible[. ]”
37+ #
38+ # -- https: //www. gnu. org /software/gawk /manual/html_node /Getline_002fPipe.html
39+
40+ c -= 1
41+ if (c == 0 ) {
42+ print " ERROR: Runaway loop looking for '}}}-->'. " > " /dev/stderr"
43+ exit 1
44+ }
45+
46+ getline
47+ } # while not '}}}'
48+
49+ } # within {{{begin …}}}
50+
51+ # }}} -->
52+ /^ * }+ * --> * $ / {
53+ print ; getline
54+ c = LOOP_MAX
55+
56+ # <!-- {{{end}}} -->
57+ while (! /^ * < ! -- * {+ end}+ * -- > * $/ ) {
58+ c -= 1
59+ if (c == 0 ) {
60+ print " ERROR: Runaway loop looking for '<!--{{{end}}}-->'. " > " /dev/stderr"
61+ exit 1
62+ }
63+
64+ getline
65+ }
66+
67+ # the order of `for (l in output)` is not defined by POSIX, so…
68+ # print "**Lines in putput: " length(output)
69+ for (i = 0 ; i < length (output); i++ ) {
70+ print output[ i]
71+ }
72+
73+ delete output
74+ }
75+
76+ {
77+ # otherwise
78+ print
79+ }
Original file line number Diff line number Diff line change 1+ Beginning stuff:
2+ <!-- {{{begin
3+ echo "Hello world!"
4+ }}} -->
5+ whatever was there before
6+ <!-- {{{end}}} -->
7+
8+ Ending stuff:
9+ <!-- {{{begin
10+ echo "-------"
11+ echo "THE END"
12+ echo "-------"
13+ }}} -->
14+ whatever was there before
15+ <!-- {{{end}}} -->
Original file line number Diff line number Diff line change 1+ Beginning stuff:
2+ <!-- {{{begin
3+ echo "Top of the mornin' to ya's!"
4+ }}} -->
5+ whatever was there before
6+ <!-- {{{end}}} -->
7+
8+ Ending stuff:
9+ <!-- {{{begin
10+ echo "-------"
11+ echo "THE END"
12+ echo "-------"
13+ }}} -->
14+ whatever was there before
15+ <!-- {{{end}}} -->
You can’t perform that action at this time.
0 commit comments