Skip to content

Instantly share code, notes, and snippets.

@frankbe
Last active August 18, 2017 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankbe/8e0fac939e1623f797e2ca09221a65e0 to your computer and use it in GitHub Desktop.
Save frankbe/8e0fac939e1623f797e2ca09221a65e0 to your computer and use it in GitHub Desktop.
bash script to edit a pgp encrypted file with the default editor
#!/usr/bin/env bash
# edit an pgp(gpg) encryped text file vith the default editor
# (1. decrypt to temp file; 2. edit temp file; 3. encrypt temp file to orgininal file; 4. delete the temp file
ORG_FILE=$1 && test -f "$ORG_FILE" || exit 1
TMP_FILE=$(mktemp)
gpg -d $ORG_FILE>$TMP_FILE && TMP_DATE=$(stat -c %y $TMP_FILE) && $EDITOR $TMP_FILE &&
test "$TMP_DATE" != "$(stat -c %y $TMP_FILE)" && gpg --yes -o $ORG_FILE -c $TMP_FILE
rm $TMP_FILE && echo done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment