You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

#!/bin/bash
# depends on pandoc-citeproc, GNU getopts
showHelp () {
cat << EOF
Usage: markdownacademic -bctih
-b, --bibliography=<filename> Set your BibTex file here
-c, --citationstyle=<filename> Set CSL style
-t, --template=<filename> Set template file (.docx)
-i, --input=<filename> 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 ""