Last active
March 6, 2016 14:05
-
-
Save malb/185a4c9703337c524c20 to your computer and use it in GitHub Desktop.
git post-commit hook for committing compiled PDFs to different branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
out="$(pwd)/out/" | |
changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD) | |
do_the_work_tex() { | |
( | |
dir="$1" | |
filename="$2" | |
extension="$3" | |
cd "$dir" | |
latexmk -xelatex -pdf -shell-escape "$filename.$extension" | |
mkdir -p "$out/$dir" | |
cp "$filename.pdf" "$out/$dir/$filename.pdf" | |
) | |
} | |
commit_the_work() { | |
( | |
unset GIT_INDEX_FILE | |
unset GIT_WORK_TREE | |
unset GIT_DIR | |
commit_msg=$(git log -1 --pretty=oneline) | |
cd "$out" | |
git add -A | |
git commit -a -m "source: $commit_msg" | |
) | |
} | |
for fullfile in $changed_files; do | |
dir=$(dirname "$fullfile") | |
filename=$(basename "$fullfile") | |
extension="${filename##*.}" | |
filename=$(basename "$fullfile" ".$extension") | |
if [ "$extension" = "tex" ]; then | |
do_the_work_tex "$dir" "$filename" "$extension" | |
fi | |
done | |
commit_the_work | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
unset GIT_INDEX_FILE | |
unset GIT_WORK_TREE | |
unset GIT_DIR | |
out="$(pwd)/out" | |
cd "$out" | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment