From fcfe9a46b13ebc357ab3f534536623ab75107efb Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Thu, 2 Apr 2015 12:56:03 +0300 Subject: [PATCH] vimcrypted --- bin/vimcrypted | 1 + vim/vimcrypted | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) create mode 120000 bin/vimcrypted diff --git a/bin/vimcrypted b/bin/vimcrypted new file mode 120000 index 0000000..c6bf227 --- /dev/null +++ b/bin/vimcrypted @@ -0,0 +1 @@ +../vim/vimcrypted \ No newline at end of file diff --git a/vim/vimcrypted b/vim/vimcrypted index 97fad6c..0cd9528 100755 --- a/vim/vimcrypted +++ b/vim/vimcrypted @@ -5,24 +5,36 @@ # this script only takes care of storing the file # encrypted +function helpexit() { + echo "Edit a GPG encrypted file with vim. +Unsecure implementation, since the file is saved + IN PLAIN TEXT when editing, +this script only takes care of storing the file +encrypted -if [ ! -f "$1" ] -then - echo "Give me an encrypted text file" - exit 1 -fi -unc=($(echo "$1" | sed 's/.gpg$//')) -if [ "$1" = "$unc" ] +Changed file is always backed up as .old +" + exit +} +[[ -z "$1" ]] && helpexit +[[ "$1" = "-h" ]] && helpexit +set -x +if [[ ! "$1" == *\.gpg ]] then echo "source is not .gpg" exit 1 fi +unc="${1%.gpg}" if [ -e "$unc" ] then echo "$unc already exists. exiting" exit 1 fi - -gpg --decrypt "$1" > "$unc" +if [ ! -e "$1" ] +then echo "File $1 does not exist. Creating empty file" + echo " " > "$unc" +else + gpg --decrypt "$1" > "$unc" +fi edit=`date +%s -r $unc` if [ -s "$unc" ] @@ -36,10 +48,10 @@ afteredit=`date +%s -r "$unc"` if (( $edit != $afteredit )) then - cat "$unc" | gpg -ca > "$1".tmp + cat "$unc" | gpg -ca > "$1".tmp if [ -s "$1".tmp ] - then mv "$1" "$1".old - mv "$1".tmp "$1" + then [[ -e "$1" ]] && mv -f "$1" "$1".old + mv -f "$1".tmp "$1" fi fi rm "$unc"