106 lines
2.5 KiB
Bash
106 lines
2.5 KiB
Bash
#!/bin/bash
|
|
# -*- sh-mode -*-
|
|
|
|
DEFAULT_MANDIR=/bread/man
|
|
DEFAULT_MANSECTION=bread
|
|
DEFAULT_COOKBOOKDIR=/bread/cookbook
|
|
|
|
usage() {
|
|
prog="${BASH_SOURCE[0]}"
|
|
cat <<ENDUSAGE
|
|
$prog: easily write recipes and bread-related stuff
|
|
OPTIONS
|
|
-h show this help
|
|
-d DIR specify a manual directory. Default: "$DEFAULT_MANDIR"
|
|
-s SECTION specify a manual section. Default: "$DEFAULT_MANSECTION"
|
|
-e RECIPE edit a recipe. Will search $COOKBOOKDIR for RECIPE.
|
|
ENDUSAGE
|
|
}
|
|
|
|
template() { # template TITLE HEADER FOOTER
|
|
name="$1"
|
|
header="$2"
|
|
footer="$3"
|
|
upname="$(echo "$name" | tr a-z A-Z)"
|
|
cat <<ENDTEMPLATE
|
|
% $upname($MANSECTION) $header | $footer
|
|
% $USER
|
|
|
|
# NAME
|
|
|
|
**$name** -- makes <!--YIELD-->
|
|
|
|
time
|
|
~ <!--TIME-->
|
|
|
|
# DESCRIPTION
|
|
<!-- introductory notes, history, or tips go here
|
|
DON'T make it very long!
|
|
You can add extra notes in the NOTES section. -->
|
|
|
|
|
|
# INGREDIENTS
|
|
<!-- ingredients should be listed as bullet points in this format:
|
|
- <Quantity> <Measurement> <Ingredient>, <Preperation>
|
|
Where Quantity is a number, Measurement is something like cups or grams,
|
|
Ingredient is the ... ingredient, and Preparation is
|
|
what you need to do to prepare the ingredient, like dicing, etc.
|
|
Preparation is optional, and Measurement should only be used when you're measuring.
|
|
-->
|
|
|
|
|
|
# METHOD
|
|
<!-- List out the method here, in full paragraphs.
|
|
Look at other recipes for style.
|
|
-->
|
|
|
|
|
|
<!-- OPTIONAL: # NOTES -->
|
|
<!-- If you'd like to include extra notes about the recipe, put them here. -->
|
|
ENDTEMPLATE
|
|
}
|
|
|
|
mk_manpage() { #mk_manpage FILE OUTNAME
|
|
pandoc -t man -f markdown -s "$1" -o "$MANDIR/man$MANSECTION/$2.$MANSECTION"
|
|
}
|
|
|
|
mk_webpage() { #mk_webpage FILE OUTNAME
|
|
pandoc -t html -f markdown "$1"
|
|
}
|
|
|
|
main() {
|
|
while getopts hd:s:e: opt; do
|
|
case "$opt" in
|
|
h) usage ;;
|
|
d) MANDIR="$OPTARG" ;;
|
|
s) MANSECTION="$OPTARG" ;;
|
|
e) # edit existing
|
|
# TODO
|
|
return
|
|
;;
|
|
*)
|
|
usage
|
|
return 2
|
|
;;
|
|
esac
|
|
done
|
|
: "${MANDIR:=$DEFAULT_MANDIR}"
|
|
: "${MANSECTION:=$DEFAULT_MANSECTION}"
|
|
: "${COOKBOOKDIR:=$DEFAULT_COOKBOOKDIR}"
|
|
|
|
read -p "Title? " title
|
|
|
|
f="/bread/cookbook/$(echo "$title" | sed 's/\W\+/-/g').md"
|
|
template "$title" "breadpunk cookbook" "$title recipe" >"$f"
|
|
|
|
"$EDITOR" "$f"
|
|
|
|
mk_manpage "$f"
|
|
|
|
mk_webpage "$f"
|
|
}
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi
|