-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-manpage
executable file
·41 lines (34 loc) · 884 Bytes
/
gen-manpage
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
#!/usr/bin/env sh
# generates a man file from readme.md using pandoc
pandoc --version 2>&1 > /dev/null || {
printf '\e[1m%s\e[0m\n' \
'Please install pandoc if you want a man file.' 1>&2
exit 1
}
{
# generate man page frontmatter
# troff man header: .TH "title" "section no." "date" "footer" "header"
ver="$(./kagami --version | egrep -o 'v([0-9].?)+' | head -n 1)"
cat <<- EOF
---
title: kagami
section: 1
header: User Commands
footer: $ver
date: $(git log -1 --format='%ad')
---
# NAME
$(./kagami --version | head -n 1 | sed "s/$ver//")
# SYNOPSIS
kagami [OPTIONS]
# DESCRIPTION
EOF
# omit github specific headings
# capitalize <h1> document headings
sed -E -e '1,/8</d' -e 's/^(# .*)/\U\1/g' < readme.md
# append author information
cat <<- EOF
# AUTHOR
$(./kagami --version | head -n 2 | tail -n 1)
EOF
} | pandoc - -s -t man -o -