#!/bin/bash if [ $# -lt 1 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ] then echo "pandoc2handlebars.sh FILE [FILE...] Converts (partially) the given Pandoc templates to Handlebars files. Hand edit the \$for(var)\$ and other unconverted bits. " exit 1 fi for FN in "$@" do # Verify or skip [ -f "$FN" ] || echo "WARNING: '$FN' is not a file. (skipping)" 1>&2 [ -f "$FN" ] || continue [ -f "${FN}.handlebars" ] && echo "WARNING: Refusing to overwrite '${FN}.handlebars' (skipping)" 1>&2 [ -f "${FN}.handlebars" ] && continue sed -E 's/\$endif\$/{{\/if}}/g;s/\$if\(([^\)]*)\)\$/{{#if \1}}/g;s/\$([A-Za-z][A-Za-z0-9.]*)\$/{{\1}}/g' <"$FN" >"${FN}.handebars" done