Skip to content

Instantly share code, notes, and snippets.

@grubernd
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grubernd/00adcaac3e36ba576727 to your computer and use it in GitHub Desktop.
Save grubernd/00adcaac3e36ba576727 to your computer and use it in GitHub Desktop.
convert Commonmark files into manpages
#!/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