Bill Jonas on Tue, 31 Jul 2001 23:03:03 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Have Vim transparently handle encrypted files


On Tue, Jul 31, 2001 at 09:02:03PM -0400, Bill Jonas wrote:
> Oh, and there was another problem with a plaintext copy of the file
> being left lying around.  I fixed the problem, too.  I'm attaching a
> copy of the corrected version.

Okay.  I've done some improvements yet again.

One issue has been resolved, that is, the fact that a cleartext copy of
the file you're editing exists while vim is active.  I've solved that
problem.  Now, no cleartext copy exists while you're editing.  (But see
below about the swap file.)

As far as other problems that currently still exist...

Some of the output from gpg is left on the screen after writing but not
exiting.  As a work-around, hit CTRL-L to redraw the screen.

I don't believe the swap file is encrypted.

I'm not sure exactly what actions trigger the FileAppend* events, so
those are not tested.  When they do get executed, though, a cleartext
copy of the file exists on disk temporarily.


...So I ask again, any comments?  :)

-- 
Bill Jonas    *    bill@billjonas.com    *    http://www.billjonas.com/
"As we enjoy great advantages from the inventions of others,  we should
be glad of an opportunity to serve others by any invention of ours; and
this we should do freely and generously."          -- Benjamin Franklin
if has("autocmd")

" Support editing of gpg-encrypted files
augroup gnupg
  " Remove all gnupg autocommands
  au!

  " Enable editing of gpg-encrypted files
  " Inspired from the gzip section of Debian's /etc/vimrc
  " By Bill Jonas, bill@billjonas.com
  "	  read:	set binary mode before reading the file
  "		decrypt text in buffer after reading
  "	 write:	encrypt file after writing
  "	append:	decrypt file, append, encrypt file
  autocmd BufReadPre,FileReadPre	*.gpg,*.asc set bin
  autocmd BufReadPre,FileReadPre	*.gpg,*.asc let ch_save = &ch|set ch=2
  autocmd BufReadPost,FileReadPost	*.gpg,*.asc 1;'[,']!gpg -d 2>/dev/null
  autocmd BufReadPost,FileReadPost	*.gpg,*.asc set nobin
  autocmd BufReadPost,FileReadPost	*.gpg,*.asc execute ":doautocmd BufReadPost " . expand("%:r")
  autocmd BufReadPost,FileReadPost	*.gpg,*.asc let &ch = ch_save|unlet ch_save

  autocmd BufWritePre,FileWritePre	*.gpg,*.asc set bin
  autocmd BufWritePre,FileWritePre	*.gpg 1;'[,']!gpg -o - -e
  autocmd BufWritePre,FileWritePre	*.asc 1;'[,']!gpg -a -o - -e
  autocmd BufWritePost,FileWritePost	*.gpg,*.asc set nobin
  autocmd BufWritePost,FileWritePost	*.gpg,*.asc undo

  autocmd FileAppendPre			*.gpg,*.asc !gpg -d <afile> 2>/dev/null ><afile>:r
  autocmd FileAppendPre			*.gpg,*.asc !mv <afile>:r <afile>
  autocmd FileAppendPost		*.gpg,*.asc !mv <afile> <afile>:r
  autocmd FileAppendPost		*.gpg !gpg -o <afile> -e <afile>:r
  autocmd FileAppendPost		*.asc !gpg -a -o <afile> -e <afile>:r
  autocmd FileAppendPost		*.gpg,*.asc !rm <afile>:r
augroup END

endif