#!/bin/bash # depends on pandoc-citeproc, GNU getopts showHelp () { cat << EOF Usage: markdownacademic -bctih -b, --bibliography= Set your BibTex file here -c, --citationstyle= Set CSL style -t, --template= Set template file (.docx) -i, --input= Select markdown file as input -h, --help Display this help message Unless specified, output file has the same name as the input file. EOF } SHORT=b:c:t:i:o::h LONG=bibliography:,citationstyle:,template:,input:,output,help # read the options OPTS=$(getopt --options $SHORT --long $LONG --name "$0" -- "$@") if [ $? != 0 ] ; then echo "Failed to parse options...exiting." >&2 ; exit 1 ; fi eval set -- "$OPTS" # extract options and their arguments into variables. while true ; do case "$1" in -b | --bibliography ) BIBLIOGRAPHY="$2" shift 2 ;; -c | --citationstyle ) CITATIONSTYLE="$2" shift 2 ;; -t | template ) TEMPLATE="$2" shift 2 ;; -i | input ) FILE="$2" shift 2 ;; -h | help ) showHelp exit 0 ;; --) shift ; break;; *) if [-z "$1" ]; then break; else showHelp ; exit 0; fi;; esac done # Print the variables #echo $BIBLIOGRAPHY #echo $CITATIONSTYLE #echo $TEMPLATE #echo $FILE pandoc --verbose -s --filter=/usr/bin/pandoc-citeproc --bibliography="$BIBLIOGRAPHY" --csl=$CITATIONSTYLE --reference-doc="$TEMPLATE" -f markdown -t docx --output="$(basename "$FILE" .md).docx" "$FILE" echo -e "" echo -e "\e[0;32mSuccess!\e[0m Output file is \e[0;33m$(basename "$FILE" .md).docx\e[0m" echo -e ""