Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 15 commits
  • 1 file changed
  • 0 commit comments
  • 4 contributors
Commits on Jul 28, 2014
@jamessan jamessan Ensure b:GPGRecipients is initialized to a list value
Closes #18
Signed-off-by: James McCoy <vega.james@gmail.com>
a1bc9f1
Commits on Aug 10, 2014
@jamessan jamessan Put --homedir at the start of the command line
Closes jamessan/vim-gnupg#20
Signed-off-by: James McCoy <vega.james@gmail.com>
40cec46
Commits on Oct 09, 2014
@tyll tyll Add g:GPGRecipientsMenu
Allow to set initial contents for recipients menu with
g:GPGRecipientsMenu. Example usage:

let g:GPGRecipientsMenu=""
    \."GPG: Example User <example@example.com>\<NL>"
    \."GPG: Other User <otherexample@example.com>\<NL>"
22f68e7
Commits on Oct 29, 2014
Sebastian Neumann Refactor g:GPGRecipientsMenu to use list and rename to g:GPGPossibleR…
…ecipients

  let g:GPGPossibleRecipients=[
    \"Example User <example@example.com>",
    \"Other User <otherexample@example.com>"
  \]
d316155
Commits on Nov 21, 2014
@jamessan jamessan Force Vim to re-setup the terminal after running a command
After Vim runs certain commands (e.g., pinentry-curses), the terminal is
not returned to its previous state.  This causes some escape sequences,
like arrow keys, to stop being recognized properly by Vim.

Re-setting &term to itself causes Vim to go through its normal terminal
initialization steps which gets things back in working order.

Closes jamessan/vim-gnupg#17
Signed-off-by: James McCoy <vega.james@gmail.com>
bd3ebdf
@jamessan jamessan Merge pull request #21 from tyll/menu
Add g:GPGRecipientsMenu
2099978
Commits on Dec 25, 2014
@blueyed blueyed Trigger BufWritePost event via BufWriteCmd/FileWriteCmd
Closes jamessan/vim-gnupg#23
Signed-off-by: James McCoy <vega.james@gmail.com>
28c6e91
@jamessan jamessan Emit FileWritePre/Post events when handling FileWriteCmd
Signed-off-by: James McCoy <vega.james@gmail.com>
9de82fa
@jamessan jamessan Don't change modified state of buffer for FileWriteCmd
Signed-off-by: James McCoy <vega.james@gmail.com>
3c01375
Commits on Jan 06, 2015
@jamessan jamessan Emit BufReadPre/FileReadPre when decrypting the file
Signed-off-by: James McCoy <vega.james@gmail.com>
30a4987
@jamessan jamessan Manually set [ and ] marks after decrypting
:lockmarks doesn't appear to preserve these marks.  They would need
to be adjusted anyway due to the line numbers changing, so just set the
marks to the start/end of the buffer.

Signed-off-by: James McCoy <vega.james@gmail.com>
cdf98c6
@jamessan jamessan Trigger FileReadPost event after decrypting for :r
Signed-off-by: James McCoy <vega.james@gmail.com>
380f05d
Commits on Feb 06, 2015
@jamessan jamessan Emit TermChanged when resetting &term
Resetting &term can affect various settings which are terminal
dependent (e.g., escape sequences described at “:help :set-termcap”).
Emitting TermChanged allows people to re-set these options so they don't
lose functionality (c.f. jamessan/vim-gnupg#28).

Signed-off-by: James McCoy <vega.james@gmail.com>
671b846
Commits on Mar 03, 2015
@jamessan jamessan Document that GPGSystem always uses temp files
Signed-off-by: James McCoy <vega.james@gmail.com>
553f919
Commits on Mar 22, 2015
@jamessan jamessan Silence "No matching autocommands" for TermChanged event
Signed-off-by: James McCoy <vega.james@gmail.com>
dd8e4ad
Showing with 99 additions and 52 deletions.
  1. +99 −52 plugin/gnupg.vim
View
151 plugin/gnupg.vim
@@ -1,5 +1,5 @@
" Name: gnupg.vim
-" Last Change: 2013 Sep 09
+" Last Change: 2015 Mar 21
" Maintainer: James McCoy <vega.james@gmail.com>
" Original Author: Markus Braun <markus.braun@krawel.de>
" Summary: Vim plugin for transparent editing of gpg encrypted files.
@@ -95,6 +95,17 @@
" If set, these recipients are used as defaults when no other recipient is
" defined. This variable is a Vim list. Default is unset.
"
+" g:GPGPossibleRecipients
+" If set, these contents are loaded into the recipients dialog. This
+" allows to add commented lines with possible recipients to the list,
+" which can be uncommented to select the actual recipients. Example:
+"
+" let g:GPGPossibleRecipients=[
+" \"Example User <example@example.com>",
+" \"Other User <otherexample@example.com>"
+" \]
+"
+"
" 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
@@ -175,21 +186,16 @@ augroup GnuPG
" do the decryption
exe "autocmd BufReadCmd " . g:GPGFilePattern . " call s:GPGInit(1) |" .
- \ " call s:GPGDecrypt(1) |" .
- \ " call s:GPGBufReadPost()"
+ \ " call s:GPGDecrypt(1) |"
exe "autocmd FileReadCmd " . g:GPGFilePattern . " call s:GPGInit(0) |" .
\ " call s:GPGDecrypt(0)"
" convert all text to encrypted text before writing
" We check for GPGCorrespondingTo to avoid triggering on writes in GPG Options/Recipient windows
- exe "autocmd BufWriteCmd " . g:GPGFilePattern . " if !exists('b:GPGCorrespondingTo') |" .
- \ " call s:GPGBufWritePre() |" .
- \ " endif"
-
exe "autocmd BufWriteCmd,FileWriteCmd " . g:GPGFilePattern . " if !exists('b:GPGCorrespondingTo') |" .
- \ " call s:GPGInit(0) |" .
- \ " call s:GPGEncrypt() |" .
- \ " endif"
+ \ " call s:GPGInit(0) |" .
+ \ " call s:GPGEncrypt() |" .
+ \ " endif"
" cleanup on leaving vim
exe "autocmd VimLeave " . g:GPGFilePattern . " call s:GPGCleanup()"
@@ -274,6 +280,11 @@ function s:GPGInit(bufread)
let g:GPGDefaultRecipients = []
endif
+ if (!exists("g:GPGPossibleRecipients"))
+ let g:GPGPossibleRecipients = []
+ endif
+
+
" prefer not to use pipes since it can garble gpg agent display
if (!exists("g:GPGUsePipes"))
let g:GPGUsePipes = 0
@@ -400,7 +411,14 @@ function s:GPGDecrypt(bufread)
let filename = expand("<afile>:p")
" clear GPGRecipients and GPGOptions
- let b:GPGRecipients = copy(g:GPGDefaultRecipients)
+ if type(g:GPGDefaultRecipients) == type([])
+ let b:GPGRecipients = copy(g:GPGDefaultRecipients)
+ else
+ let b:GPGRecipients = []
+ echohl GPGWarning
+ echom "g:GPGDefaultRecipients is not a Vim list, please correct this in your vimrc!"
+ echohl None
+ endif
let b:GPGOptions = []
" File doesn't exist yet, so nothing to decrypt
@@ -491,6 +509,14 @@ function s:GPGDecrypt(bufread)
return
endif
+ if a:bufread
+ silent execute ':doautocmd BufReadPre ' . fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called BufReadPre autocommand for ' . fnameescape(expand('<afile>:r')))
+ else
+ silent execute ':doautocmd FileReadPre ' . fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called FileReadPre autocommand for ' . fnameescape(expand('<afile>:r')))
+ endif
+
" check if the message is armored
if (match(output, "gpg: armor header") >= 0)
call s:GPGDebug(1, "this file is armored")
@@ -518,47 +544,36 @@ function s:GPGDecrypt(bufread)
return
endif
- " refresh screen
- redraw!
-
- call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
-endfunction
+ if a:bufread
+ " In order to make :undo a no-op immediately after the buffer is read,
+ " we need to do this dance with 'undolevels'. Actually discarding the undo
+ " history requires performing a change after setting 'undolevels' to -1 and,
+ " luckily, we have one we need to do (delete the extra line from the :r
+ " command)
+ let levels = &undolevels
+ set undolevels=-1
+ " :lockmarks doesn't actually prevent '[,'] from being overwritten, so we
+ " need to manually set them ourselves instead
+ silent 1delete
+ 1mark [
+ $mark ]
+ let &undolevels = levels
+ " call the autocommand for the file minus .gpg$
+ silent execute ':doautocmd BufReadPost ' . fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called BufReadPost autocommand for ' . fnameescape(expand('<afile>:r')))
+ else
+ " call the autocommand for the file minus .gpg$
+ silent execute ':doautocmd FileReadPost ' . fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called FileReadPost autocommand for ' . fnameescape(expand('<afile>:r')))
+ endif
-" Function: s:GPGBufReadPost() {{{2
-"
-" Handle functionality specific to opening a file for reading rather than
-" reading the contents of a file into a buffer
-"
-function s:GPGBufReadPost()
- call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufReadPost()")
- " In order to make :undo a no-op immediately after the buffer is read,
- " we need to do this dance with 'undolevels'. Actually discarding the undo
- " history requires performing a change after setting 'undolevels' to -1 and,
- " luckily, we have one we need to do (delete the extra line from the :r
- " command)
- let levels = &undolevels
- set undolevels=-1
- silent 1delete
- let &undolevels = levels
" Allow the user to define actions for GnuPG buffers
silent doautocmd User GnuPG
- " call the autocommand for the file minus .gpg$
- silent execute ':doautocmd BufReadPost ' . fnameescape(expand('<afile>:r'))
- call s:GPGDebug(2, 'called BufReadPost autocommand for ' . fnameescape(expand('<afile>:r')))
- call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGBufReadPost()")
-endfunction
-" Function: s:GPGBufWritePre() {{{2
-"
-" Handle functionality specific to saving an entire buffer to a file rather
-" than saving a partial buffer
-"
-function s:GPGBufWritePre()
- call s:GPGDebug(3, ">>>>>>>> Entering s:GPGBufWritePre()")
- " call the autocommand for the file minus .gpg$
- silent execute ':doautocmd BufWritePre ' . fnameescape(expand('<afile>:r'))
- call s:GPGDebug(2, 'called autocommand for ' . fnameescape(expand('<afile>:r')))
- call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGBufWritePre()")
+ " refresh screen
+ redraw!
+
+ call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGDecrypt()")
endfunction
" Function: s:GPGEncrypt() {{{2
@@ -568,6 +583,19 @@ endfunction
function s:GPGEncrypt()
call s:GPGDebug(3, ">>>>>>>> Entering s:GPGEncrypt()")
+ " FileWriteCmd is only called when a portion of a buffer is being written to
+ " disk. Since Vim always sets the '[,'] marks to the part of a buffer that
+ " is being written, that can be used to determine whether BufWriteCmd or
+ " FileWriteCmd triggered us.
+ if [line("'["), line("']")] == [1, line('$')]
+ let auType = 'BufWrite'
+ else
+ let auType = 'FileWrite'
+ endif
+
+ silent exe ':doautocmd '. auType .'Pre '. fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called '. auType .'Pre autocommand for ' . fnameescape(expand('<afile>:r')))
+
" store encoding and switch to a safe one
if (&fileencoding != &encoding)
let s:GPGEncoding = &encoding
@@ -656,7 +684,13 @@ function s:GPGEncrypt()
endif
call rename(destfile, resolve(expand('<afile>')))
- setl nomodified
+ if auType == 'BufWrite'
+ setl nomodified
+ endif
+
+ silent exe ':doautocmd '. auType .'Post '. fnameescape(expand('<afile>:r'))
+ call s:GPGDebug(2, 'called '. auType .'Post autocommand for ' . fnameescape(expand('<afile>:r')))
+
call s:GPGDebug(3, "<<<<<<<< Leaving s:GPGEncrypt()")
endfunction
@@ -797,6 +831,10 @@ function s:GPGEditRecipients()
let syntaxPattern = '\(' . join(flaggedNames, '\|') . '\)'
endif
+ for line in g:GPGPossibleRecipients
+ silent put ='GPG: '.line
+ endfor
+
" define highlight
if (has("syntax") && exists("g:syntax_on"))
highlight clear GPGUnknownRecipient
@@ -1248,11 +1286,18 @@ function s:GPGPostCmd()
let &shellredir = s:shellredirsave
let &shell = s:shellsave
let &shelltemp = s:shelltempsave
+ " Workaround a bug in the interaction between console vim and
+ " pinentry-curses by forcing Vim to re-detect and setup its terminal
+ " settings
+ let &term = &term
+ silent doautocmd TermChanged
endfunction
" Function: s:GPGSystem(dict) {{{2
"
-" run g:GPGCommand using system(), logging the commandline and output
+" run g:GPGCommand using system(), logging the commandline and output. This
+" uses temp files (regardless of how 'shelltemp' is set) to hold the output of
+" the command, so it must not be used for sensitive commands.
" Recognized keys are:
" level - Debug level at which the commandline and output will be logged
" args - Arguments to be given to g:GPGCommand
@@ -1260,10 +1305,11 @@ endfunction
" Returns: command output
"
function s:GPGSystem(dict)
- let commandline = printf('%s %s', s:GPGCommand, a:dict.args)
+ let commandline = s:GPGCommand
if (!empty(g:GPGHomedir))
let commandline .= ' --homedir ' . shellescape(g:GPGHomedir)
endif
+ let commandline .= ' ' . a:dict.args
let commandline .= ' ' . s:stderrredirnull
call s:GPGDebug(a:dict.level, "command: ". commandline)
@@ -1286,10 +1332,11 @@ endfunction
" redirect - Shell redirect to use, if needed
"
function s:GPGExecute(dict)
- let commandline = printf('%s%s %s', a:dict.ex, s:GPGCommand, a:dict.args)
+ let commandline = printf('%s%s', a:dict.ex, s:GPGCommand)
if (!empty(g:GPGHomedir))
let commandline .= ' --homedir ' . shellescape(g:GPGHomedir, 1)
endif
+ let commandline .= ' ' . a:dict.args
if (has_key(a:dict, 'redirect'))
let commandline .= ' ' . a:dict.redirect
endif

No commit comments for this range

Something went wrong with that request. Please try again.