Last active
August 29, 2015 14:14
-
-
Save grubernd/00adcaac3e36ba576727 to your computer and use it in GitHub Desktop.
convert Commonmark files into manpages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#----------------------------------------------------------- | |
# Copyright (C) 2015 GRUBERND http://grubernd.at | |
# released under a FreeBSD License | |
# | |
# converts commonmark files into man pages | |
# http://commonmark.org/ | |
# dependencies: cmark | |
# | |
# the cmark files are expected to be named like this: | |
# commandname.x.mkd | |
# where x is the section according to | |
# https://www.kernel.org/doc/man-pages/ | |
#----------------------------------------------------------- | |
documentationfolder="./docs" | |
manpagefolder="./usr_share_man" | |
[[ ! -d "$manpagefolder" ]] && mkdir -p "$manpagefolder" | |
cd "$documentationfolder" | |
for cmarkfile in *.mkd; do | |
manfile=${cmarkfile%.*} | |
manname=${manfile%.*} | |
mannumber=${manfile##*.} | |
case $mannumber in | |
"1") centralheader="User Command";; | |
"2") centralheader="System Call Documentation";; | |
"3") centralheader="Library Function";; | |
"4") centralheader="Device Document";; | |
"5") centralheader="File Format Description";; | |
"7") centralheader="General Information Overview";; | |
"8") centralheader="Superuser / System Administration Command";; | |
*) centralheader="Unknown Category";; | |
esac | |
filedate=$(stat -c %y $cmarkfile | cut -d ' ' -f1) | |
echo -e ".TH $manname $mannumber \"$filedate\" \"\" \"$centralheader\"" > "../$manpagefolder/$manfile" | |
cmark "$cmarkfile" --to man >> "../$manpagefolder/$manfile" | |
done | |
cd ../ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment