Skip to content

Commit

Permalink
Script fixed based on shellcheck.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlday committed Jun 12, 2018
1 parent db09514 commit 5aeb5a2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions bin/shunnshort.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#!/usr/bin/env bash

# This script can be symlinked to. I link to in from $HOME/.local/bin

# Rule 1: Do only what's necessary in Pandoc

# Figure out where everything is
SCRIPT=$(realpath $0)
SCRIPT_PATH=$(dirname $SCRIPT)
PANDOC_TEMPLATES=$(dirname $SCRIPT_PATH)
SCRIPT="$(realpath "$0")"
SCRIPT_PATH="$(dirname "$SCRIPT")"
PANDOC_TEMPLATES="$(dirname "$SCRIPT_PATH")"
SHUNN_SHORT_STORY_DIR="$PANDOC_TEMPLATES/shunn/short"

# Create a temporary data directory
echo "Creating temporary directory."
export PANDOC_DATA_DIR=$(mktemp -d)
export PANDOC_DATA_DIR
PANDOC_DATA_DIR="$(mktemp -d)"
echo "Directory created: $PANDOC_DATA_DIR"

# Prep the template and reference directories
echo "Extracting $SHUNN_SHORT_STORY_DIR/template.docx to temporary directory."
unzip -ao $SHUNN_SHORT_STORY_DIR/template.docx -d $PANDOC_DATA_DIR/template > /dev/null
unzip -ao $SHUNN_SHORT_STORY_DIR/template.docx -d $PANDOC_DATA_DIR/reference > /dev/null
unzip -ao "$SHUNN_SHORT_STORY_DIR/template.docx" -d "$PANDOC_DATA_DIR/template" > /dev/null
unzip -ao "$SHUNN_SHORT_STORY_DIR/template.docx" -d "$PANDOC_DATA_DIR/reference" > /dev/null
echo "Files extracted."

# Run pandoc
echo "Running Pandoc."
pandoc $1 \
pandoc "$1" \
--from markdown \
--to docx \
--lua-filter $SHUNN_SHORT_STORY_DIR/shunnshort.lua \
--data-dir $PANDOC_DATA_DIR \
--output $2
--lua-filter "$SHUNN_SHORT_STORY_DIR/shunnshort.lua" \
--data-dir "$PANDOC_DATA_DIR" \
--output "$2"
echo "Pandoc completed successfully."

# Clean up the temporary directory
echo "Removing $PANDOC_DATA_DIR"
rm -rf $PANDOC_DATA_DIR
rm -rf "$PANDOC_DATA_DIR"
echo "Done."

0 comments on commit 5aeb5a2

Please sign in to comment.