vimcrypted
This commit is contained in:
1
bin/vimcrypted
Symbolic link
1
bin/vimcrypted
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../vim/vimcrypted
|
||||||
@@ -5,24 +5,36 @@
|
|||||||
# this script only takes care of storing the file
|
# this script only takes care of storing the file
|
||||||
# encrypted
|
# 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" ]
|
Changed file is always backed up as .old
|
||||||
then
|
"
|
||||||
echo "Give me an encrypted text file"
|
exit
|
||||||
exit 1
|
}
|
||||||
fi
|
[[ -z "$1" ]] && helpexit
|
||||||
unc=($(echo "$1" | sed 's/.gpg$//'))
|
[[ "$1" = "-h" ]] && helpexit
|
||||||
if [ "$1" = "$unc" ]
|
set -x
|
||||||
|
if [[ ! "$1" == *\.gpg ]]
|
||||||
then
|
then
|
||||||
echo "source is not .gpg"
|
echo "source is not .gpg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
unc="${1%.gpg}"
|
||||||
if [ -e "$unc" ]
|
if [ -e "$unc" ]
|
||||||
then echo "$unc already exists. exiting"
|
then echo "$unc already exists. exiting"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ ! -e "$1" ]
|
||||||
|
then echo "File $1 does not exist. Creating empty file"
|
||||||
|
echo " " > "$unc"
|
||||||
|
else
|
||||||
gpg --decrypt "$1" > "$unc"
|
gpg --decrypt "$1" > "$unc"
|
||||||
|
fi
|
||||||
|
|
||||||
edit=`date +%s -r $unc`
|
edit=`date +%s -r $unc`
|
||||||
if [ -s "$unc" ]
|
if [ -s "$unc" ]
|
||||||
@@ -38,8 +50,8 @@ if (( $edit != $afteredit ))
|
|||||||
then
|
then
|
||||||
cat "$unc" | gpg -ca > "$1".tmp
|
cat "$unc" | gpg -ca > "$1".tmp
|
||||||
if [ -s "$1".tmp ]
|
if [ -s "$1".tmp ]
|
||||||
then mv "$1" "$1".old
|
then [[ -e "$1" ]] && mv -f "$1" "$1".old
|
||||||
mv "$1".tmp "$1"
|
mv -f "$1".tmp "$1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
rm "$unc"
|
rm "$unc"
|
||||||
|
|||||||
Reference in New Issue
Block a user