-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-readme.sh
executable file
·43 lines (34 loc) · 1.3 KB
/
gen-readme.sh
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
#!/bin/bash
# Pass script file through "help extract" and format into markdown detais.
bin-details() {
bin=$(basename $1)
printf '<details>\n<summary>`%s`</summary>\n\n```\n%s\n```\n</details>\n' \
$bin "$(zbx.-h $1 NO_ANSI 100)"
}
update-marker() {
marker=$1
tmpfile=$(mktemp)
# There must be newline soon after marker, because of how it renders.
echo "" > $tmpfile
cat /dev/stdin >> $tmpfile
# Delete between all output markers.
sed -i "/{{{OUTPUT-$marker/,/}}}/{//!d}" ./readme.md
# Marker line number.
line=$(sed -n "/{{{OUTPUT-$marker/=" ./readme.md)
# Splice tempfile into readme file.
sed -i "$line r $tmpfile" ./readme.md
rm $tmpfile
}
# Scripts: help output of ./bin executables that has that "zbx-script-header" line, others are considered to be WIP.
for bin in $(find bin -maxdepth 1 -type f -executable | sort );do
grep -q '^source zbx-script-header$' $bin && bin-details $bin
done | update-marker scripts
# Git-hooks:
for bin in $(find git.hooks -type f -executable | sort );do
bin-details $bin
done | update-marker git-hooks
# Todo list:
dirs=(bin build cfg git.hooks tmpl)
for dir in ${dirs[*]};do
grep -n --recursive TODO $dir
done | sort | echo -e '<details>\n\n```'"\n$(cat /dev/stdin)\n"'```\n</details>' | update-marker TODO