2010-01-27 08:18:04 -05:00
|
|
|
|
" Name: gnupg.vim
|
2019-02-03 23:23:47 -05:00
|
|
|
|
" Last Change: 2019 Feb 03
|
2016-04-24 23:04:21 -04:00
|
|
|
|
" Maintainer: James McCoy <jamessan@jamessan.com>
|
2011-05-24 07:28:02 -04:00
|
|
|
|
" Original Author: Markus Braun <markus.braun@krawel.de>
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Summary: Vim plugin for transparent editing of gpg encrypted files.
|
2011-05-24 07:28:02 -04:00
|
|
|
|
" License: This program is free software; you can redistribute it and/or
|
|
|
|
|
" modify it under the terms of the GNU General Public License
|
|
|
|
|
" as published by the Free Software Foundation; either version
|
|
|
|
|
" 2 of the License, or (at your option) any later version.
|
|
|
|
|
" See http://www.gnu.org/copyleft/gpl-2.0.txt
|
2010-01-27 08:18:04 -05:00
|
|
|
|
"
|
2003-05-30 09:29:16 -04:00
|
|
|
|
" Section: Documentation {{{1
|
2010-01-27 08:18:04 -05:00
|
|
|
|
"
|
|
|
|
|
" Description: {{{2
|
2009-05-27 07:10:20 -04:00
|
|
|
|
"
|
2006-12-15 13:09:40 -05:00
|
|
|
|
" This script implements transparent editing of gpg encrypted files. The
|
|
|
|
|
" filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such
|
2003-06-24 07:57:16 -04:00
|
|
|
|
" a file the content is decrypted, when opening a new file the script will
|
|
|
|
|
" ask for the recipients of the encrypted file. The file content will be
|
|
|
|
|
" encrypted to all recipients before it is written. The script turns off
|
2012-05-30 22:15:46 -04:00
|
|
|
|
" viminfo, swapfile, and undofile to increase security.
|
2003-05-30 09:29:16 -04:00
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Installation: {{{2
|
2003-05-30 09:29:16 -04:00
|
|
|
|
"
|
|
|
|
|
" Copy the gnupg.vim file to the $HOME/.vim/plugin directory.
|
|
|
|
|
" Refer to ':help add-plugin', ':help add-global-plugin' and ':help
|
|
|
|
|
" runtimepath' for more details about Vim plugins.
|
|
|
|
|
"
|
2008-07-31 11:43:14 -04:00
|
|
|
|
" From "man 1 gpg-agent":
|
|
|
|
|
"
|
|
|
|
|
" ...
|
|
|
|
|
" You should always add the following lines to your .bashrc or whatever
|
|
|
|
|
" initialization file is used for all shell invocations:
|
|
|
|
|
"
|
2009-05-27 07:10:20 -04:00
|
|
|
|
" GPG_TTY=`tty`
|
2008-07-31 11:43:14 -04:00
|
|
|
|
" export GPG_TTY
|
|
|
|
|
"
|
|
|
|
|
" It is important that this environment variable always reflects the out‐
|
|
|
|
|
" put of the tty command. For W32 systems this option is not required.
|
|
|
|
|
" ...
|
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Most distributions provide software to ease handling of gpg and gpg-agent.
|
|
|
|
|
" Examples are keychain or seahorse.
|
|
|
|
|
"
|
2013-04-23 22:15:45 -04:00
|
|
|
|
" If there are specific actions that should take place when editing a
|
|
|
|
|
" GnuPG-managed buffer, an autocmd for the User event and GnuPG pattern can
|
|
|
|
|
" be defined. For example, the following will set 'textwidth' to 72 for all
|
|
|
|
|
" GnuPG-encrypted buffers:
|
|
|
|
|
"
|
|
|
|
|
" autocmd User GnuPG setl textwidth=72
|
|
|
|
|
"
|
|
|
|
|
" This will be triggered before any BufRead or BufNewFile autocmds, and
|
|
|
|
|
" therefore will not take precedence over settings specific to any filetype
|
|
|
|
|
" that may get set.
|
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Commands: {{{2
|
2003-05-30 09:29:16 -04:00
|
|
|
|
"
|
|
|
|
|
" :GPGEditRecipients
|
|
|
|
|
" Opens a scratch buffer to change the list of recipients. Recipients that
|
2006-12-15 13:09:40 -05:00
|
|
|
|
" are unknown (not in your public key) are highlighted and have
|
|
|
|
|
" a prepended "!". Closing the buffer makes the changes permanent.
|
2003-05-30 09:29:16 -04:00
|
|
|
|
"
|
|
|
|
|
" :GPGViewRecipients
|
|
|
|
|
" Prints the list of recipients.
|
|
|
|
|
"
|
2006-12-15 13:09:40 -05:00
|
|
|
|
" :GPGEditOptions
|
|
|
|
|
" Opens a scratch buffer to change the options for encryption (symmetric,
|
|
|
|
|
" asymmetric, signing). Closing the buffer makes the changes permanent.
|
|
|
|
|
" WARNING: There is no check of the entered options, so you need to know
|
|
|
|
|
" what you are doing.
|
|
|
|
|
"
|
|
|
|
|
" :GPGViewOptions
|
|
|
|
|
" Prints the list of options.
|
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Variables: {{{2
|
2006-12-15 13:09:40 -05:00
|
|
|
|
"
|
2008-07-31 11:43:14 -04:00
|
|
|
|
" g:GPGExecutable
|
2015-12-11 07:26:50 -05:00
|
|
|
|
" If set used as gpg executable. If unset, defaults to
|
|
|
|
|
" "gpg --trust-model always" if "gpg" is available, falling back to
|
|
|
|
|
" "gpg2 --trust-model always" if not.
|
2008-07-31 11:43:14 -04:00
|
|
|
|
"
|
2006-12-15 13:09:40 -05:00
|
|
|
|
" g:GPGUseAgent
|
|
|
|
|
" If set to 0 a possible available gpg-agent won't be used. Defaults to 1.
|
|
|
|
|
"
|
2007-03-01 09:58:04 -05:00
|
|
|
|
" g:GPGPreferSymmetric
|
|
|
|
|
" If set to 1 symmetric encryption is preferred for new files. Defaults to 0.
|
|
|
|
|
"
|
|
|
|
|
" g:GPGPreferArmor
|
2010-02-16 07:56:18 -05:00
|
|
|
|
" If set to 1 armored data is preferred for new files. Defaults to 0
|
|
|
|
|
" unless a "*.asc" file is being edited.
|
2007-03-01 09:58:04 -05:00
|
|
|
|
"
|
2009-05-27 07:10:20 -04:00
|
|
|
|
" g:GPGPreferSign
|
|
|
|
|
" If set to 1 signed data is preferred for new files. Defaults to 0.
|
|
|
|
|
"
|
2008-08-15 12:50:33 -04:00
|
|
|
|
" g:GPGDefaultRecipients
|
|
|
|
|
" If set, these recipients are used as defaults when no other recipient is
|
|
|
|
|
" defined. This variable is a Vim list. Default is unset.
|
|
|
|
|
"
|
2014-10-29 11:53:59 -04:00
|
|
|
|
" g:GPGPossibleRecipients
|
2014-10-09 10:48:03 -04:00
|
|
|
|
" If set, these contents are loaded into the recipients dialog. This
|
|
|
|
|
" allows to add commented lines with possible recipients to the list,
|
2015-10-03 10:26:29 -04:00
|
|
|
|
" which can be uncommented to select the actual recipients. Default is
|
|
|
|
|
" unset. Example:
|
2014-10-09 10:48:03 -04:00
|
|
|
|
"
|
2014-10-29 11:53:59 -04:00
|
|
|
|
" let g:GPGPossibleRecipients=[
|
|
|
|
|
" \"Example User <example@example.com>",
|
|
|
|
|
" \"Other User <otherexample@example.com>"
|
|
|
|
|
" \]
|
2014-10-09 10:48:03 -04:00
|
|
|
|
"
|
|
|
|
|
"
|
2011-08-01 20:44:17 -04:00
|
|
|
|
" g:GPGUsePipes
|
|
|
|
|
" If set to 1, use pipes instead of temporary files when interacting with
|
|
|
|
|
" gnupg. When set to 1, this can cause terminal-based gpg agents to not
|
|
|
|
|
" display correctly when prompting for passwords. Defaults to 0.
|
|
|
|
|
"
|
2011-11-23 17:09:42 -05:00
|
|
|
|
" g:GPGHomedir
|
|
|
|
|
" If set, specifies the directory that will be used for GPG's homedir.
|
|
|
|
|
" This corresponds to gpg's --homedir option. This variable is a Vim
|
2015-10-03 10:26:29 -04:00
|
|
|
|
" string. Default is unset.
|
2011-11-23 17:09:42 -05:00
|
|
|
|
"
|
2013-02-10 11:59:44 -05:00
|
|
|
|
" g:GPGFilePattern
|
|
|
|
|
" If set, overrides the default set of file patterns that determine
|
|
|
|
|
" whether this plugin will be activated. Defaults to
|
|
|
|
|
" '*.\(gpg\|asc\|pgp\)'.
|
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Known Issues: {{{2
|
2009-05-27 07:10:20 -04:00
|
|
|
|
"
|
2010-02-16 07:56:18 -05:00
|
|
|
|
" In some cases gvim can't decrypt files
|
2009-05-27 07:10:20 -04:00
|
|
|
|
|
|
|
|
|
" This is caused by the fact that a running gvim has no TTY and thus gpg is
|
|
|
|
|
" not able to ask for the passphrase by itself. This is a problem for Windows
|
|
|
|
|
" and Linux versions of gvim and could not be solved unless a "terminal
|
|
|
|
|
" emulation" is implemented for gvim. To circumvent this you have to use any
|
|
|
|
|
" combination of gpg-agent and a graphical pinentry program:
|
|
|
|
|
"
|
|
|
|
|
" - gpg-agent only:
|
|
|
|
|
" you need to provide the passphrase for the needed key to gpg-agent
|
|
|
|
|
" in a terminal before you open files with gvim which require this key.
|
|
|
|
|
"
|
|
|
|
|
" - pinentry only:
|
|
|
|
|
" you will get a popup window every time you open a file that needs to
|
|
|
|
|
" be decrypted.
|
|
|
|
|
"
|
|
|
|
|
" - gpgagent and pinentry:
|
|
|
|
|
" you will get a popup window the first time you open a file that
|
|
|
|
|
" needs to be decrypted.
|
|
|
|
|
"
|
2015-12-04 19:20:48 -05:00
|
|
|
|
" If you're using Vim <7.4.959, after the plugin runs any external command,
|
|
|
|
|
" Vim will no longer be able to yank to/paste from the X clipboard or
|
|
|
|
|
" primary selections. This is caused by a workaround for a different bug
|
|
|
|
|
" where Vim no longer recognizes the key codes for keys such as the arrow
|
|
|
|
|
" keys after running GnuPG. See the discussion at
|
|
|
|
|
" https://github.com/jamessan/vim-gnupg/issues/36 for more details.
|
|
|
|
|
"
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Credits: {{{2
|
2009-05-27 07:10:20 -04:00
|
|
|
|
"
|
|
|
|
|
" - Mathieu Clabaut for inspirations through his vimspell.vim script.
|
|
|
|
|
" - Richard Bronosky for patch to enable ".pgp" suffix.
|
|
|
|
|
" - Erik Remmelzwaal for patch to enable windows support and patient beta
|
|
|
|
|
" testing.
|
|
|
|
|
" - Lars Becker for patch to make gpg2 working.
|
2010-02-16 07:56:18 -05:00
|
|
|
|
" - Thomas Arendsen Hein for patch to convert encoding of gpg output.
|
2009-05-27 07:10:20 -04:00
|
|
|
|
" - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model
|
|
|
|
|
" and patient beta testing.
|
|
|
|
|
" - Giel van Schijndel for patch to get GPG_TTY dynamically.
|
|
|
|
|
" - Sebastian Luettich for patch to fix issue with symmetric encryption an set
|
|
|
|
|
" recipients.
|
2010-02-16 07:56:18 -05:00
|
|
|
|
" - Tim Swast for patch to generate signed files.
|
|
|
|
|
" - James Vega for patches for better '*.asc' handling, better filename
|
|
|
|
|
" escaping and better handling of multiple keyrings.
|
2006-12-15 13:09:40 -05:00
|
|
|
|
"
|
2003-05-30 09:29:16 -04:00
|
|
|
|
" Section: Plugin header {{{1
|
2008-07-31 11:43:14 -04:00
|
|
|
|
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" guard against multiple loads {{{2
|
2012-05-31 00:31:56 -04:00
|
|
|
|
if (exists("g:loaded_gnupg") || &cp || exists("#GnuPG"))
|
2006-12-15 13:09:40 -05:00
|
|
|
|
finish
|
2008-07-31 11:43:14 -04:00
|
|
|
|
endif
|
2018-08-06 23:16:53 -04:00
|
|
|
|
let g:loaded_gnupg = '2.7.0-dev'
|
2008-07-31 11:43:14 -04:00
|
|
|
|
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" check for correct vim version {{{2
|
2011-05-24 01:16:05 -04:00
|
|
|
|
if (v:version < 702)
|
|
|
|
|
echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.2' | echohl None
|
2010-02-16 07:56:18 -05:00
|
|
|
|
finish
|
|
|
|
|
endif
|
2003-05-30 09:29:16 -04:00
|
|
|
|
|
|
|
|
|
" Section: Autocmd setup {{{1
|
2010-01-27 08:18:04 -05:00
|
|
|
|
|
2013-02-05 04:38:25 -05:00
|
|
|
|
if (!exists("g:GPGFilePattern"))
|
|
|
|
|
let g:GPGFilePattern = '*.\(gpg\|asc\|pgp\)'
|
|
|
|
|
endif
|
|
|
|
|
|
2003-05-30 09:29:16 -04:00
|
|
|
|
augroup GnuPG
|
2008-07-31 11:43:14 -04:00
|
|
|
|
autocmd!
|
|
|
|
|
|
|
|
|
|
" do the decryption
|
2019-02-03 23:23:47 -05:00
|
|
|
|
exe "autocmd BufReadCmd " . g:GPGFilePattern . " call gnupg#init(1) |" .
|
|
|
|
|
\ " call gnupg#decrypt(1)"
|
|
|
|
|
exe "autocmd FileReadCmd " . g:GPGFilePattern . " call gnupg#init(0) |" .
|
|
|
|
|
\ " call gnupg#decrypt(0)"
|
2008-07-31 11:43:14 -04:00
|
|
|
|
|
|
|
|
|
" convert all text to encrypted text before writing
|
2013-02-22 14:51:18 -05:00
|
|
|
|
" We check for GPGCorrespondingTo to avoid triggering on writes in GPG Options/Recipient windows
|
|
|
|
|
exe "autocmd BufWriteCmd,FileWriteCmd " . g:GPGFilePattern . " if !exists('b:GPGCorrespondingTo') |" .
|
2019-02-03 23:23:47 -05:00
|
|
|
|
\ " call gnupg#init(0) |" .
|
|
|
|
|
\ " call gnupg#encrypt() |" .
|
2014-12-25 15:11:31 -05:00
|
|
|
|
\ " endif"
|
2003-05-30 09:29:16 -04:00
|
|
|
|
augroup END
|
2008-01-23 09:49:33 -05:00
|
|
|
|
|
2003-05-30 09:29:16 -04:00
|
|
|
|
" Section: Highlight setup {{{1
|
2010-01-27 08:18:04 -05:00
|
|
|
|
|
2006-12-15 13:09:40 -05:00
|
|
|
|
highlight default link GPGWarning WarningMsg
|
|
|
|
|
highlight default link GPGError ErrorMsg
|
|
|
|
|
highlight default link GPGHighlightUnknownRecipient ErrorMsg
|
2008-01-23 09:49:33 -05:00
|
|
|
|
|
2010-01-27 08:18:04 -05:00
|
|
|
|
" Section: Commands {{{1
|
|
|
|
|
|
2019-02-03 23:23:47 -05:00
|
|
|
|
command! GPGViewRecipients call gnupg#view_recipients()
|
|
|
|
|
command! GPGEditRecipients call gnupg#edit_recipients()
|
|
|
|
|
command! GPGViewOptions call gnupg#view_options()
|
|
|
|
|
command! GPGEditOptions call gnupg#edit_options()
|
2010-01-27 08:18:04 -05:00
|
|
|
|
|
2008-07-31 11:43:14 -04:00
|
|
|
|
" Section: Menu {{{1
|
2010-01-27 08:18:04 -05:00
|
|
|
|
|
2008-08-15 12:50:33 -04:00
|
|
|
|
if (has("menu"))
|
2008-07-31 11:43:14 -04:00
|
|
|
|
amenu <silent> Plugin.GnuPG.View\ Recipients :GPGViewRecipients<CR>
|
|
|
|
|
amenu <silent> Plugin.GnuPG.Edit\ Recipients :GPGEditRecipients<CR>
|
|
|
|
|
amenu <silent> Plugin.GnuPG.View\ Options :GPGViewOptions<CR>
|
|
|
|
|
amenu <silent> Plugin.GnuPG.Edit\ Options :GPGEditOptions<CR>
|
|
|
|
|
endif
|
2009-05-27 07:10:20 -04:00
|
|
|
|
|
|
|
|
|
" vim600: set foldmethod=marker foldlevel=0 :
|