Commit Graph

250 Commits

Author SHA1 Message Date
James McCoy
6b56cdceda Clear GPGOptions/GPGRecipients autocommands on BufUnload
The BufHidden autocommand will have already called the respective Finish
function.  Clearing the autocommands during BufUnload ensures they don't
inadvertently run when Vim is shutting down.

Closes jamessan/vim-gnupg#104
2020-11-11 13:11:52 -05:00
James McCoy
1537043c19 Start new bug fix release 2020-11-11 13:11:30 -05:00
James McCoy
a72ab0b1e0 release vim-gnupg version 2.7.0
Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-09 22:27:59 -05:00
James McCoy
970823aba6 Ignore asc/gpg files
These are typically test files, but a good idea not to accidentally add
encrypted files to the repo.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-09 22:27:59 -05:00
James McCoy
9ba5fc2485 Exclude git metadata from exports
Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-09 22:27:58 -05:00
James McCoy
647b29d9db Update URL to GPL-2 license
Reported-by: magicbrothers <felix@felix-zauberer.de>
Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-09 13:01:18 -05:00
James McCoy
313e645f1c Merge branch 'debug' into main 2020-11-09 12:56:56 -05:00
James McCoy
1f7b93af08 Document how to provide debug info and what it contains
Closes jamessan/vim-gnupg#61
Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-07 23:17:58 -05:00
James McCoy
c8de2bb17c Respect the 'verbose' option
This allows for easier on-the-fly debug (e.g., ":verbose w") and also
makes it easy to leverage 'verbosefile'.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-11-07 23:16:20 -05:00
James McCoy
90b86c542c Ignore doc/tags
Closes: jamessan/vim-gnupg#113
Signed-off-by: James McCoy <jamessan@jamessan.com>
2020-09-07 19:03:23 -04:00
James McCoy
f663d0e857 Merge branch 'tty-cmd-cleanup'
* Delete all output from "tty" command
* Do not try to run tty command if it doesn't exist
2019-08-25 09:51:28 -04:00
James McCoy
5001a8b45d Do not try to run tty command if it doesn't exist
Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-08-23 19:02:29 -04:00
James McCoy
c2c9720584 Delete all output from "tty" command
Instead of assuming a single line is output, which may be wrong in error
conditions, use the '[/'] marks to delete everything that was read.

Closes jamessan/vim-gnupg#106
Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-08-23 18:57:20 -04:00
James McCoy
6219a5a0d7 Use proper pattern for g:GPGFilePattern
Per |file-pattern|, autocmds use glob-like syntax for patterns, not
regular expressions.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-05-30 21:56:08 -04:00
James McCoy
35d2692139 Merge branch 'Koronen/move-documentation' 2019-04-08 23:19:03 -04:00
James McCoy
32360c8f20 Define GPGEdit{Options,Recipients} autocmd in their own group
This allows them to be properly cleared only when the buffer is
re-created/loaded.  This fixes the handling of the autocmds when the
Edit buffer is saved, but not hidden or deleted.

The autocmd remains in place, rather than having an acwrite buffer with
no autocmd set.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-02-11 23:23:14 -05:00
James McCoy
d90ae08795 Use a common function to create GPGEdit{Options,Recipients} buffer
Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-02-11 23:06:01 -05:00
James McCoy
db08c3873f Convert last s:GPGEditRecipients() to gnupg#edit_recipients()
Closes: jamessan/vim-gnupg#98
Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-02-04 09:01:59 -05:00
James McCoy
44372d80cd Move implementation into autoload/gnupg.vim
Closes: jamessan/vim-gnupg#52
Closes: jamessan/vim-gnupg#66

Signed-off-by: James McCoy <jamessan@jamessan.com>
2019-02-03 23:33:50 -05:00
James McCoy
08c4f516e8 Merge branch 'distinct-bufwritecmd' 2018-11-27 20:47:46 -05:00
James McCoy
161485e835 Only use ":'[,']w" for FileWriteCmd
BufWriteCmd writes the whole buffer, so it can use the bare ":w".  Other
plugins may manipulate the '[/'] marks on save, which can cause the
write with marks to not write the entire buffer.

Closes: jamessan/vim-gnupg#96
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-11-18 09:57:15 -05:00
James McCoy
22cbc6b6ab Start development on 2.7.0
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-08-06 23:16:53 -04:00
James McCoy
966808db82 vim-gnupg version 2.6.1
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-08-06 23:06:39 -04:00
James McCoy
9e69ba79be Detect armored files by checking for an armor header line
Closes jamessan/vim-gnupg#82
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-08-06 23:03:29 -04:00
James McCoy
7fcea1a084 Simplify list handling in GPGView{Options,Recipients}
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-06-22 22:32:53 -04:00
James McCoy
e2aec69d2d Use buffer number to name the options/recipients buffers
Since buffer numbers are unique in Vim, there's no concern about
collisions between options/recipients buffers for different encrypted
buffers.

This also resolves an issue where opening the options buffer would
trigger the recipients buffer (due to the buffer name matching
g:GPGFilePattern.

Closes jamessan/vim-gnupg#89
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-06-22 21:53:51 -04:00
James McCoy
fa3a63039d Show an error if FileReadCmd can't open the file
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-01-23 22:20:03 -05:00
James McCoy
6be6f96aa5 Do not set buftype=acwrite for FileReadCmd
FileReadCmd reads the contents of another file into the current buffer.
Therefore, it should honor the settings ('buftype' and :file) of the
current buffer.

Closes jamessan/vim-gnupg#86
Signed-off-by: James McCoy <jamessan@jamessan.com>
2018-01-23 22:06:27 -05:00
James McCoy
b54fd4c18a Merge branch 'fnameescape' 2017-12-15 18:12:37 -05:00
James McCoy
599a039254 fnameescape() paths for constructed commands
Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-12-15 14:44:04 -05:00
James McCoy
5b069789e2 Merge branch 'autochdir' 2017-10-24 20:28:32 -04:00
James McCoy
c411e61aeb On save, only unset 'modified' for the current filename
If the buffer is being saved to a different filename, then this buffer
should still be modified as its backing file is still different than the
buffer.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-10-22 23:24:22 -04:00
James McCoy
d3453145c5 Set the buffer name to the resolved, absolute path
If buftype=acwrite, Vim doesn't adjust relative buffer names when
changing directory.  Since 5103285d, encrypted buffers have set
buftype=acwrite and therefore also risked having incorrect buffer names
(e.g., if 'autochdir' is set).

Now that the buffer name is always fully resolved, this should no longer
be a problem.

Closes jamessan/vim-gnupg#81
Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-10-22 23:24:09 -04:00
James McCoy
ae1b31965e Ensure buftype=acwrite is always set for the buffer
The user may be a) editing an existing encrypted file, b) creating a new
encrypted file, c) editing an unnamed buffer and saving it as an
encrypted file.  In all cases, 'buftype' should be set correctly once we
know the buffer is intended to be encrypted.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-10-22 23:16:28 -04:00
James McCoy
e7b6648ab2 Merge branch 'gpg4win' 2017-05-31 22:24:26 -04:00
James McCoy
9d600d73fa Support using vim-gnupg from cygwin with Gpg4win
Gpg4win expects native Windows paths even when it's being run from a
cygwin environment.  In order to satisfy that, update `s:shellescape` to
know whether it should convert the paths to native Windows paths using
`cygpath -am`.

In order to detect whether cygpath should be invoked, look for the
combination of `has('win32unix')` being true and `gpg --version`
reporting a Windows style path for gpg's home directory.

Closes jamessan/vim-gnupg#62

Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-05-31 00:37:06 -04:00
James McCoy
5103285d4d Set "buftype=acwrite" for encrypted buffers
This ensures any write of the buffer requires a configured BufWriteCmd
autocmd, providing more safe guards against problems like
jamessan/vim-gnupg#77.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-02-14 22:12:05 -05:00
James McCoy
7d0a149169 Remove GPGCleanup function
If 'autowrite' is set, an encrypted buffer is modified, and ":q!"/"ZQ"
is executed, GPGCleanup's "only!" would cause the buffer to be
abandoned.  Due to 'autowrite' and the VimLeave autocmd not using
"nested", abandoning the buffer causes Vim to write the buffer, which is
currently unencrypted, overwriting the encrypted file with plain text.

Since the user can more reliably clear their own console/terminal scroll
back than we can, simply remove this functionality.  It's safer than
trying to unwind the twisty passages of Vim's autocmds, especially those
of the *WriteCmd variety.

Closes jamessan/vim-gnupg#77
Signed-off-by: James McCoy <jamessan@jamessan.com>
2017-02-14 22:11:52 -05:00
James McCoy
fa18ce0c9e Use non-fnameescape()d filenames in logs
Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-12-18 01:14:28 -05:00
James McCoy
d279115bcd GPGDecrypt: Handle (un)encrypted files consistently
In the refactor to use the *Cmd events, an unencrypted file was simply
:read into the buffer.  This incorrectly caused an extra blank line to
be added to the top of the buffer.

The handling of encrypted files properly handles this, as well as
triggering BufRead(Pre,Post) events.

Instead of returning early for unencrypted files, go through the same
steps as for encrypted files (minus the encryption specific steps), thus
preserving the content of the original file.
2016-12-17 22:05:17 -05:00
James McCoy
be052843ef Add s:unencrypted function to consolidate "unencrypted buffer" check
Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-12-17 21:14:35 -05:00
James McCoy
45fdaf52ed GPGCleanup: Use "only!" to force hiding modified buffers
In dda14abb3c, GPGCleanup added 'set
buffhidden=hide' to try avoiding error messages when modified buffers
are being abandoned.  However, that only works if the buffer is the last
visible buffer.

If there are windows displaying multiple buffers, then errors can still
be emitted.  Using "only!" ensures all the other windows can be closed.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-12-17 20:51:26 -05:00
James McCoy
dda14abb3c GPGCleanup: Allow the buffer to be hidden on exit
When Vim has decided it can exit, GPGCleanup forces a blank buffer to
take over the screen so contents aren't visible in scrollback.  However,
if the buffer is modified and 'hidden' isn't set then the command will
fail.

Force the buffer to be hidden, so this is avoided.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-12-14 23:05:40 -05:00
James McCoy
e7be112873 GPGEdit{Recipients,Options}: Check for presence of b:GPGCorrespondingTo
Since the user can control which file patterns are handled by the plugin
(via g:GPGFilePattern), the regular expression checking the buffer name
for GPGEdit{Recipients,Options} may not match.  A simpler and more
definitive check is to see whether b:GPGCorrespondingTo is set to
determine if the buffer is an existing recipients/options buffer.

Closes jamessan/vim-gnupg#72
Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-12-04 14:07:36 -05:00
James McCoy
454090fe40 GPGEncrypt: Remove (file)encoding dance around file encryption
Changing &encoding when &fileencoding != &encoding causes two problems.

First, it's completely unsafe to change &encoding after vim is running,
since there may be characters that can't be translated from one encoding
to another, which can make vim crash.

Second, this actually loses information about the buffer's encoding.
When the encrypted file is opened later, it won't be in the same
encoding as before it was saved.  Changing user's data on them is
unacceptable.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-09-18 15:22:06 -04:00
James McCoy
22cca0c821 Use “:read ++edit !...” so file encoding/format detection triggers
Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-09-17 22:45:31 -04:00
James McCoy
28e0be4cd2 Maintain 'readonly' if it's already set
If the user is using "vim -R"/":view", then the opened buffer should
have 'readonly' set, even if permissions would otherwise allow editing.

Closes jamessan/vim-gnupg#67

Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-08-25 21:38:56 -04:00
James McCoy
541e333cfb Stop setting g:GPGPreferArmor in GPGInit
When the user hasn't explicity let g:GPGPreferArmor, the value is
supposed to be determined by the filename.  Instead of letting
g:GPGPreferArmor, lazily determine what should be done when actually
doing the encryption.

Signed-off-by: James McCoy <jamessan@jamessan.com>
2016-04-24 23:27:34 -04:00
James McCoy
2dfb82f13e Handle rename() failures
Renaming the temporary, encrypted file to the intended filename (per the
buffer) may fail (e.g., typoed directory name).  In this case, remove
the temporary file and then give the typical error message for this
situation.

In order to be safe, the message is manually being generated instead of
trying to be clever and do something like “noautocmd write” expecting it
to hit the same error that rename() did.

Closes jamessan/vim-gnupg#56
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-12-17 21:52:12 -05:00
Scott Stevenson
c2ddc05bc2 Fall back to gpg2 if gpg is not available
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-12-11 20:47:17 -05:00