Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 18 commits
  • 1 file changed
  • 0 commit comments
  • 5 contributors
Commits on Sep 10, 2013
@nachoalonso nachoalonso Use filereadable() instead of glob() to detect whether a file exists.
glob() reports false positives if the filename has metacharacters in it
(e.g., "[...]"), which causes Vim to incorrectly open a new, blank
buffer instead of the specified file.

Closes jamessan/vim-gnupg#12

Signed-off-by: James McCoy <vega.james@gmail.com>
6e9f52a
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
Commits on Jul 17, 2015
@jamessan jamessan Setup agent handling after determining gnupg's version
Starting with release 2.1, gnupg will automatically run gpg-agent rather
than requiring it to be run as a daemon.  The “--no-use-agent” switch
was also marked deprecated, since it no longer does anything.

This commit moves the --(no-)use-agent handling until after it is known
what version of gpg is being used.

Closes #37

Signed-off-by: James McCoy <vega.james@gmail.com>
ac5d945
Commits on Jul 26, 2015
@jamessan jamessan Remove “--batch” from command used to detect encryption
If the “log-file” option is set in ~/.gnupg/gpg.conf, then using “--batch”
means that the CLI's “--logger-fd” is ignored.  Since this command
shouldn't need any of “--batch”'s functionality and “log-file” hides all
the output we're expecting, dropping “--batch” is the sane thing to do.

Closes #40

Signed-off-by: James McCoy <vega.james@gmail.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
#	modified:   plugin/gnupg.vim
#
# Untracked files:
#	foo.asc
#	foo.gpg
#	foo.sig
#
# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git c/plugin/gnupg.vim i/plugin/gnupg.vim
index 80f2061..b0bcd5c 100644
--- c/plugin/gnupg.vim
+++ i/plugin/gnupg.vim
@@ -1,5 +1,5 @@
 " Name:    gnupg.vim
-" Last Change: 2015 Jul 16
+" Last Change: 2015 Jul 26
 " 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.
@@ -448,7 +448,7 @@ function s:GPGDecrypt(bufread)

   " find the recipients of the file
   let cmd = { 'level': 3 }
-  let cmd.args = '--verbose --decrypt --list-only --dry-run --batch --no-use-agent --logger-fd 1 ' . shellescape(filename)
+  let cmd.args = '--verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 ' . shellescape(filename)
   let output = s:GPGSystem(cmd)

   " Suppress the "N more lines" message when editing a file, not when reading
8394f2e
Showing with 134 additions and 84 deletions.
  1. +134 −84 plugin/gnupg.vim
View
218 plugin/gnupg.vim
@@ -1,5 +1,5 @@
" Name: gnupg.vim
-" Last Change: 2013 Jun 14
+" Last Change: 2015 Jul 26
" 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
@@ -287,36 +298,7 @@ function s:GPGInit(bufread)
" print version
call s:GPGDebug(1, "gnupg.vim ". g:loaded_gnupg)
- " determine if gnupg can use the gpg-agent
- if (exists("$GPG_AGENT_INFO") && g:GPGUseAgent == 1)
- if (!exists("$GPG_TTY") && !has("gui_running"))
- " Need to determine the associated tty by running a command in the
- " shell. We can't use system() here because that doesn't run in a shell
- " connected to a tty, so it's rather useless.
- "
- " Save/restore &modified so the buffer isn't incorrectly marked as
- " modified just by detecting the correct tty value.
- " Do the &undolevels dance so the :read and :delete don't get added into
- " the undo tree, as the user needn't be aware of these.
- let [mod, levels] = [&l:modified, &undolevels]
- set undolevels=-1
- silent read !tty
- let $GPG_TTY = getline('.')
- silent delete
- let [&l:modified, &undolevels] = [mod, levels]
- " redraw is needed since we're using silent to run !tty, c.f. :help :!
- redraw!
- if (v:shell_error)
- let $GPG_TTY = ""
- echohl GPGWarning
- echom "$GPG_TTY is not set and the `tty` command failed! gpg-agent might not work."
- echohl None
- endif
- endif
- let s:GPGCommand = g:GPGExecutable . " --use-agent"
- else
- let s:GPGCommand = g:GPGExecutable . " --no-use-agent"
- endif
+ let s:GPGCommand = g:GPGExecutable
" don't use tty in gvim except for windows: we get their a tty for free.
" FIXME find a better way to avoid an error.
@@ -361,11 +343,43 @@ function s:GPGInit(bufread)
" find the supported algorithms
let output = s:GPGSystem({ 'level': 2, 'args': '--version' })
+ let gpgversion = substitute(output, '^gpg (GnuPG) \([0-9]\+\.\d\+\).*', '\1', '')
let s:GPGPubkey = substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "")
let s:GPGCipher = substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "")
let s:GPGHash = substitute(output, ".*Hash: \\(.\\{-}\\)\n.*", "\\1", "")
let s:GPGCompress = substitute(output, ".*Compress.\\{-}: \\(.\\{-}\\)\n.*", "\\1", "")
+ " determine if gnupg can use the gpg-agent
+ if (str2float(gpgversion) >= 2.1 || (exists("$GPG_AGENT_INFO") && g:GPGUseAgent == 1))
+ if (!exists("$GPG_TTY") && !has("gui_running"))
+ " Need to determine the associated tty by running a command in the
+ " shell. We can't use system() here because that doesn't run in a shell
+ " connected to a tty, so it's rather useless.
+ "
+ " Save/restore &modified so the buffer isn't incorrectly marked as
+ " modified just by detecting the correct tty value.
+ " Do the &undolevels dance so the :read and :delete don't get added into
+ " the undo tree, as the user needn't be aware of these.
+ let [mod, levels] = [&l:modified, &undolevels]
+ set undolevels=-1
+ silent read !tty
+ let $GPG_TTY = getline('.')
+ silent delete
+ let [&l:modified, &undolevels] = [mod, levels]
+ " redraw is needed since we're using silent to run !tty, c.f. :help :!
+ redraw!
+ if (v:shell_error)
+ let $GPG_TTY = ""
+ echohl GPGWarning
+ echom "$GPG_TTY is not set and the `tty` command failed! gpg-agent might not work."
+ echohl None
+ endif
+ endif
+ let s:GPGCommand = s:GPGCommand . " --use-agent"
+ else
+ let s:GPGCommand = s:GPGCommand . " --no-use-agent"
+ endif
+
call s:GPGDebug(2, "public key algorithms: " . s:GPGPubkey)
call s:GPGDebug(2, "cipher algorithms: " . s:GPGCipher)
call s:GPGDebug(2, "hashing algorithms: " . s:GPGHash)
@@ -400,11 +414,18 @@ 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
- if empty(glob(filename))
+ if !filereadable(filename)
" Allow the user to define actions for GnuPG buffers
silent doautocmd User GnuPG
" call the autocommand for the file minus .gpg$
@@ -427,7 +448,7 @@ function s:GPGDecrypt(bufread)
" find the recipients of the file
let cmd = { 'level': 3 }
- let cmd.args = '--verbose --decrypt --list-only --dry-run --batch --no-use-agent --logger-fd 1 ' . shellescape(filename)
+ let cmd.args = '--verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 ' . shellescape(filename)
let output = s:GPGSystem(cmd)
" Suppress the "N more lines" message when editing a file, not when reading
@@ -491,6 +512,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 +547,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 +586,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 +687,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 +834,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 +1289,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 +1308,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 +1335,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.