-
-
Save morimori/90720 to your computer and use it in GitHub Desktop.
ファイルを作成・編集する際に、ロード前の復号、セーブ後の暗号化を自動で行う
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
#! /bin/sh | |
if [ -z "$EDITOR" ]; then | |
echo "EDITOR is not set." | |
exit 1 | |
fi | |
TMPFILE="${TMPDIR}secuedit.$$" | |
NEW=0 | |
[ "-n" == "$2" ] && NEW=1 | |
if [ "$NEW" == "0" ]; then | |
openssl des3 -d -salt -in "$1" -out "$TMPFILE" | |
else | |
touch "$TMPFILE" | |
fi | |
cp -f "$TMPFILE" "$TMPFILE.orig" | |
"$EDITOR" $TMPFILE | |
diff -q "$TMPFILE.orig" "$TMPFILE" >/dev/null 2>&1 | |
if [ "$?" == "0" ]; then | |
echo "not modified." | |
else | |
[ "$NEW" == "1" ] && cp -f "$1" "$1~" | |
openssl des3 -salt -in "$TMPFILE" -out "$1" | |
fi | |
rm -f "$TMPFILE" "$TMPFILE.orig" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment