This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |