Skip to content

Instantly share code, notes, and snippets.

@curiositry
Last active March 30, 2017 17:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curiositry/27c7be05f315a7efb406f85fa503366f to your computer and use it in GitHub Desktop.
Save curiositry/27c7be05f315a7efb406f85fa503366f to your computer and use it in GitHub Desktop.
A little bash script to format manuscripts with Pandoc
#!/bin/sh
echo "Formatting manuscripts..."
for i in "$@"
do
case $i in
-f=*|--filename=*)
FILENAME="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
echo "FILENAME: ${FILENAME}"
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi
if [ ! pandoc ]; then
echo "Pandoc not found; installing..."
sudo apt install pandoc
echo "Done."
fi
if [ ! -d formatted ]; then
echo "Creating directory for formatted manuscripts ..."
mkdir formatted
echo "Done."
fi
cd formatted/
pandoc ../"${FILENAME}.md" -s --output "${FILENAME}.odt"
libreoffice "${FILENAME}.odt"
pandoc ../"${FILENAME}.md" -s --output "${FILENAME}.docx"
libreoffice "${FILENAME}.docx"
echo "Finished!"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment