1
0
Fork 0
repo2html/raw

42 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
#
# Handles formatting of raw input
#
# Copyright (C) 2012 Mike Gerwitz
#
# This file is part of repo2html.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script should be invoked after setting up the environment. The name of
# the template must be provided and the input will be accepted from stdin. The
# input up until the first empty line will be considered the subject.
# #
tpl="${1:?No template provided}"
msgfmt="${2:-cat}"
[ -x "$tpl" ] || {
echo "fatal: template '${tpl##*/}' does not exist or is not executable" >&2
exit 64
}
# grab and format the subject (the template may or may not use it); note that
# 'q' includes the line that is matched (as opposed to Q), so the sed command
# will output the newline and leave the remaining input (the body) untouched
export subject="$( sed -u '/^$/q' | "$msgfmt" -P )"
# the remainder of the input will be formatted and sent directly to the template
"$msgfmt" | "$tpl"