On 8/27/2009 3:38 PM, Byron Clark wrote:
> So, even simpler and more secure is a snippet like this in your .vimrc:
>
> if has("autocmd")
>     " gpg encrypted files
>     if exists("$KEY")
>         autocmd BufNewFile,BufReadPre *.gpg :set secure viminfo= noswapfile 
> nobackup nowritebackup       \history=0 binary
>         autocmd BufReadPost *.gpg :%!gpg -d 2>/dev/null
>         autocmd BufWritePre *.gpg :%!gpg -e -r $KEY 2>/dev/null
>         autocmd BufWritePost *.gpg u
>     endif
> endif
>   


Thanks Byron, this is much easier to use than the bash script I was 
using before.

Just a few pointers to those who would like to use script above:

1. First, remove the backslash ("   \") from the 4th line.  Vim 
complains until you remove this.

2. set the $KEY to your email address of your gpg key, and make sure you 
'export' it, or vim will not see it.  Placing "export [email protected]" 
in your ~/.bash_profile will do the trick

3. You will need to have pre-created your gpg private/public keys.  You 
can do this by executing "gpg --gen-key" and following the prompts.  The 
email address you use here will be the same you set the $KEY variable to.

4. You can create a new password/secure file by simply editing the file 
to be created "vim newfile.gpg".  Make sure the new file has the .gpg 
extension or the code above will not work.  When vim loads it will ask 
you for your private key password.  Once you enter your password, your 
password file will load.  You can then edit the file, save and quit, and 
the password file will be re-encrypted.

5. This also has the added benefit of being able to edit, via vim, any 
encrypted ".gpg" file that has your public key associated with the file 
on the fly.


Thanks again,
Kenneth


/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to