Last active
August 14, 2018 19:13
-
-
Save kcha/8bf83b3e8a6472b8ffb5a51108fb2b06 to your computer and use it in GitHub Desktop.
Backup R Markdown HTML reports
This file contains hidden or 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 | |
# | |
# Backup R Markdown authored HTML files to a "notebook" sub-directory and add | |
# a timestamp to the HTML file | |
# | |
# e.g. | |
# R_analysis.html -> notebook/R_analysis.2015-02-12.html | |
# | |
# If file is version controlled, then a short commit hash is also added. | |
HTML=$1 | |
DIR=notebook | |
if [ ! -e "$HTML" ] | |
then | |
>&2 echo "File doesn't exist!" | |
exit 1 | |
fi | |
mkdir -vp $DIR | |
# Add short git hash if available | |
HASH=`git rev-parse --short HEAD` | |
if [ $? == 0 ] | |
then | |
NEWHTML="$DIR/`basename $HTML .html`.`date +%F_%H%M -r $HTML`_$HASH.html" | |
else | |
NEWHTML="$DIR/`basename $HTML .html`.`date +%F_%H%M -r $HTML`.html" | |
fi | |
if [ -e "$NEWHTML" ] | |
then | |
echo "Up to date" | |
else | |
cp -aiv $HTML $NEWHTML | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment