Skip to content

Instantly share code, notes, and snippets.

@orangecms
Last active February 22, 2016 11:10
Show Gist options
  • Save orangecms/93aa8c5f571efcaecc93 to your computer and use it in GitHub Desktop.
Save orangecms/93aa8c5f571efcaecc93 to your computer and use it in GitHub Desktop.
simple script to edit gpg-encrypted files :)
#!/bin/bash
if [ -n "$1" ]
then
PGP_KEY_ID=CED8B95F
ENCRYPTED_FILE=${1}
TEMP_FILE=/tmp/gpg-edit-temp # TODO: test if file exists and loop through .0, .1, etc. to avoid collisions
if [ -f "$ENCRYPTED_FILE" ] # if file exists, decrypt
then
echo "Decrypting..."
gpg -o "$TEMP_FILE" -d "$ENCRYPTED_FILE"
else
echo "File does not exist, will be created by your editor."
fi
$EDITOR "$TEMP_FILE"
echo "Encrypting..."
gpg -o "$ENCRYPTED_FILE" -ear $PGP_KEY_ID "$TEMP_FILE"
rm "$TEMP_FILE"
echo "Done."
else
echo "Error: No file name given."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment