Fix usage of sed and man page on OSX

This commit is contained in:
Marc Di Luzio 2014-12-31 13:50:15 +00:00
parent 9c68372f64
commit 3f76b6430b
3 changed files with 31 additions and 19 deletions

View file

@ -1,13 +1,15 @@
#! /bin/bash
# Used to a man page from markdown
echo ".\" Man page for the ttrts project" > $4
echo ".\" this man page is auto-generated, do not edit directly" >> $4
echo ".TH TTRTS\ v$1.$2.$3 6 $(date +%Y-%m-%d) http://mdiluz.github.io/ttrts/" >> $4
# NOTE: For the OSX version of sed we use -E, which on linux appears be an undocumented switch for -r
# we also have to use [A-Za-z] instead of \w for some reason
# as well as escaped new line characters and literal tabs instead of \n and \t
# sections to section headers
# sub-sections in man page sub-sections
# 4-space lines to tabs
@ -19,13 +21,15 @@ echo ".TH TTRTS\ v$1.$2.$3 6 $(date +%Y-%m-%d) http://mdiluz.github.io/ttrts/" >
# underline mapfile opt
# ensure name section uses correct
cat "$5" \
| sed -r 's/^# (\w+)/.SH \1/g' \
| sed -r 's/^##+ (\w+)/.SS \1/g' \
| sed -r 's/^ (.*)$/\n\t\1\n/g' \
| sed -r 's/^\t//g' \
| sed -r 's/\$\{(\w+)\}/\\fB\$\1\\fR/g' \
| sed -r 's/\{(\w+)\}/\\fI\1\\fR/g' \
| sed -r 's/-----+//g' \
| sed -r 's/`(.*?)`/\\fB\1\\fR/g' \
| sed -r 's/MAPFILE/\\fImapfile\\fR/g' \
| sed -r 's/\tttrts -/\tttrts \\-/g' >> $4
| sed -E 's/^# ([A-Za-z]+)/.SH \1/g' \
| sed -E 's/^##+ ([A-Za-z]+)/.SS \1/g' \
| sed -E 's/^ (.*)$/\
\1\
/g' \
| sed -E 's/^ //g' \
| sed -E 's/\$\{([A-Za-z]+)\}/\\fB\$\1\\fR/g' \
| sed -E 's/\{([A-Za-z]+)\}/\\fI\1\\fR/g' \
| sed -E 's/-----+//g' \
| sed -E 's/`(.*)`/\\fB\1\\fR/g' \
| sed -E 's/MAPFILE/\\fImapfile\\fR/g' \
| sed -E 's/ ttrts -/ ttrts \\-/g' >> $4