Skip to content

Instantly share code, notes, and snippets.

@morimori
Forked from krayinc/lock.sh
Created April 6, 2009 11:18
Show Gist options
  • Save morimori/90720 to your computer and use it in GitHub Desktop.
Save morimori/90720 to your computer and use it in GitHub Desktop.
ファイルを作成・編集する際に、ロード前の復号、セーブ後の暗号化を自動で行う
#! /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