#!/bin/bash # Simple script for compiling/converting documents with pandoc because I can never remember how to use it # Usage: # pandoc-make html *.md usage() { cat <<-EOF Usage: $0 [output_type] [pandoc_args for file 1] [pandoc_args for file 1] [input_files] Examples: $0 pdf *.md $0 .docx *.md # leading .'s are automatically removed from the output format Note: To put a file in pandoc arguments without having it be compiled to its own document, put a './' at the start of the path to it You can have as many arg/file combinations you want The argument array is cleared between input files EOF } # Help menu (yes, I forget how to use my own programs sometimes) if [[ -z "$1" ]]; then usage && exit 1 fi if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then usage && exit fi if [[ -z "$2" ]]; then echo "error: no files specified" usage && exit 1 fi OUTPUT_FORMAT="$1" SKIP_FIRST=true # don't process the first argument, it is the output format for FILE in "$@";do $SKIP_FIRST && SKIP_FIRST=false && continue if [[ -f "$FILE" ]] && [[ "${FILE:0:2}" != "./" ]]; then pandoc -s "$FILE" "${PANDOC_ARGS[@]}" -o "${FILE%.*}.${OUTPUT_FORMAT##.}" PANDOC_ARGS=() else PANDOC_ARGS+=("$FILE") fi done # vim:et ts=3 sw=3