Skip to content

Instantly share code, notes, and snippets.

@nextlevelshit
Created January 28, 2017 16:06
Show Gist options
  • Save nextlevelshit/b8171174c8f8468df52cac580ccd6e81 to your computer and use it in GitHub Desktop.
Save nextlevelshit/b8171174c8f8468df52cac580ccd6e81 to your computer and use it in GitHub Desktop.
git hook for markdown files, that should be compiled into pdf before committing
#!/bin/bash
echo "Compiling markdown files ..."
regex="(.*)\.md"
list=$(git diff --cached --name-only --diff-filter=ACM)
while read -r line; do
if [[ $line =~ $regex ]]; then
file=${BASH_REMATCH[1]}
pandoc $file.md -o $file.pdf
# compile markdown files to pdf
git add $file.pdf
# add compiled files to commit
echo "$file.md -> $file.pdf"
fi
done <<< "$list"
echo "Finished Compiling and added files to Commit!"
exit 0
@periodicpoint
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment