Skip to content

Instantly share code, notes, and snippets.

@samrat
Last active October 12, 2018 10:18
Show Gist options
  • Save samrat/48b87e00831363f6baf4eb0e1bec34d5 to your computer and use it in GitHub Desktop.
Save samrat/48b87e00831363f6baf4eb0e1bec34d5 to your computer and use it in GitHub Desktop.
Using hledger with an Enchive encrypted file
#!/bin/bash
JOURNAL_DIR=~/code/ledger
JOURNAL_PATH=${JOURNAL_DIR}/hledger.journal
ENC_JOURNAL_PATH=${JOURNAL_PATH}.enchive
echo "Decrypting journal file..."
enchive extract $ENC_JOURNAL_PATH
digest_before=$(md5 ${JOURNAL_PATH})
hledger $@ -f $JOURNAL_PATH
hledger bal -f $JOURNAL_PATH
function encrypt_and_close() {
digest_after=$(md5 ${JOURNAL_PATH})
if ! [ "$digest_before" == "$digest_after" ]; then
echo "Encrypting journal file..."
enchive archive $JOURNAL_PATH
echo "File has changed, committing to git"
pushd $JOURNAL_DIR
git add *.enchive
git commit -m "$(date)"
git push origin master
popd
fi
echo "Removing unencrypted journal file..."
rm $JOURNAL_PATH
}
trap encrypt_and_close EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment