Skip to content

Instantly share code, notes, and snippets.

@tianon
Created March 4, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tianon/2ade87b4554ec793a673 to your computer and use it in GitHub Desktop.
Save tianon/2ade87b4554ec793a673 to your computer and use it in GitHub Desktop.
edit GPG-encrypted files reasonably
#!/bin/bash
set -e
usage() {
local s="$(basename "$0")"
echo "usage: $s [identity] [file]"
echo " ie: $s jsmith@example.com ~/some-secret-file.asc"
}
identity="$1"; shift || { usage >&2; exit 1; }
filename="$1"; shift || { usage >&2; exit 1; }
tmp="$(mktemp)"
trap "( set -x; shred -zu '$tmp' )" EXIT
if [ -s "$filename" ]; then
( set -x; gpg --decrypt --output "$tmp" --yes "$filename" )
fi
vim "$tmp"
( set -x; gpg --encrypt --armor --recipient "$identity" --output "$filename" --yes "$tmp" )
# trap shreds $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment