Edit cookbook

I'm not really using this any more, but will keep it here for reference.
This commit is contained in:
Case Duckworth 2020-11-17 23:20:39 -06:00
parent 65f0626073
commit 74869fe684
1 changed files with 22 additions and 3 deletions

View File

@ -3,6 +3,7 @@
DEFAULT_MANDIR=/bread/man
DEFAULT_MANSECTION=bread
DEFAULT_COOKBOOKDIR=/bread/cookbook
usage() {
prog="${BASH_SOURCE[0]}"
@ -12,6 +13,7 @@ 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
}
@ -19,7 +21,7 @@ template() { # template TITLE HEADER FOOTER
name="$1"
header="$2"
footer="$3"
upname="$(printf %s "$name" | tr a-z A-Z)"
upname="$(echo "$name" | tr a-z A-Z)"
cat <<ENDTEMPLATE
% $upname($MANSECTION) $header | $footer
% $USER
@ -58,12 +60,24 @@ time
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: opt; do
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
@ -72,13 +86,18 @@ main() {
done
: "${MANDIR:=$DEFAULT_MANDIR}"
: "${MANSECTION:=$DEFAULT_MANSECTION}"
: "${COOKBOOKDIR:=$DEFAULT_COOKBOOKDIR}"
read -p "Title? " title
f="$(mktemp /tmp/cookbook-XXXXXX)"
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