From c7623a05bd3dede6cafde3dbe9e835402ba75fde Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Wed, 13 Apr 2022 01:37:22 -0700 Subject: [PATCH] pandoc-make: allow for pandoc arguments --- .config/shell/bin/pandoc-make | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.config/shell/bin/pandoc-make b/.config/shell/bin/pandoc-make index 6f056ba..c77adb9 100755 --- a/.config/shell/bin/pandoc-make +++ b/.config/shell/bin/pandoc-make @@ -7,11 +7,16 @@ usage() { cat <<-EOF Usage: - $0 [output_type] [input_files] + $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 name + $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 } @@ -27,13 +32,17 @@ if [[ -z "$2" ]]; then echo "error: no files specified" usage && exit 1 fi -FORMAT="$1" -SKIP_FIRST=true + +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" ]]; then - pandoc -s "$FILE" -o "${FILE%.*}.${FORMAT##.}" + if [[ -f "$FILE" ]] && [[ "${FILE:0:2}" != "./" ]]; then + pandoc -s "$FILE" "${PANDOC_ARGS[@]}" -o "${FILE%.*}.${OUTPUT_FORMAT##.}" + PANDOC_ARGS=() + else + PANDOC_ARGS+=("$FILE") fi done