From ef2b758b59cb662673b78ffdd3cdc9522b47c0ed Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 1 May 2020 15:27:38 +0200 Subject: [PATCH] Script to generate manpages --- scripts/man.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/man.sh diff --git a/scripts/man.sh b/scripts/man.sh new file mode 100755 index 00000000..94b311cc --- /dev/null +++ b/scripts/man.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# $0: script name +# $1: input +# $2: output +[ $# -ne 2 ] && exit 1 +[ "$1" == "$2" ] && exit 2 + +# Global variables +HEADER="doc/header" +FOOTER="doc/footer" + +# Functions +function the_day() { + # $1: file + # $2: what to replace with the date + local DATE=$(date +'%B %d, %Y') + sed -i "s/$2/$DATE/g" "$1" +} + +function the_page() { + # $1: file + # $2: what to replace with the date + FILE=$(basename "$1") + FILE="${FILE%.*}" + FILE="${FILE^^}" + sed -i "s/$2/$FILE/g" "$1" +} + +function mk_manpage() { + # $1: input + # $2: output + cat $HEADER > $2 + cat $1 >> $2 + cat $FOOTER >> $2 + the_day "$2" '___DATE___' + the_page "$2" '___PAGE___' +} + +mk_manpage "$1" "$2" +exit 0 -- GitLab