Skip to content

Instantly share code, notes, and snippets.

@thanthese
Last active December 29, 2015 02:18
Show Gist options
  • Save thanthese/417d5103c1a61002ae45 to your computer and use it in GitHub Desktop.
Save thanthese/417d5103c1a61002ae45 to your computer and use it in GitHub Desktop.
Transparently edit an encrypted file.
#!/bin/bash
# Transparently edit an encrypted file.
#
# This system isn't intended to be perfectly secure but is rather intended to
# let me edit encrypted files on dropbox securely.
#
# Inspiration: https://gist.github.com/jakeonfire/9bf7ff1b08ed2c76fefc
set -e
set -o pipefail
if [ $# != 1 ]; then
echo "usage: $ edit-gpg filename"
exit 1
fi
tempfile=$(mktemp -t edit-gpg)
function cleanup {
rm $tempfile
# echo "Deleted: $tempfile"
}
trap cleanup EXIT
file=$1
read -sp "Password for '$(basename $file)': " passphrase; echo
gpg -qd --passphrase $passphrase -o $tempfile --yes $file
vim -n -i NONE -c "set filetype=txt" $tempfile
gpg -qca --passphrase $passphrase --cipher-algo AES256 -o $file --yes $tempfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment