Commit Graph

196 Commits

Author SHA1 Message Date
James McCoy
a3e4dc94d4
Set 'readonly' per the permissions of the encrypted file.
Closes jamessan/vim-gnupg#51
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-11-04 21:02:31 -05:00
Simon Ruderich
97436d1158
remove unnecessary exists check for g:GPGPreferSymmetric
The variable is always set in GPGInit().

Signed-off-by: James McCoy <vega.james@gmail.com>
2015-10-05 21:08:59 -04:00
Simon Ruderich
80fd6e4861
remove superfluous | in BufReadCmd autocmd
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-10-05 21:08:56 -04:00
Simon Ruderich
842622cbc0
use variable for fnameescape(expand('<afile>:r'))
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-10-05 21:08:52 -04:00
Simon Ruderich
39bc3f96c1
use .= where possible
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-10-05 21:08:47 -04:00
Simon Ruderich
30db0eec65
update documentation to match code, add missing defaults
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-10-05 21:08:36 -04:00
James McCoy
f12d007414
Account for 'shellslash' being set on Windows
If a user has 'shellslash' set in Windows, then filename related
functionality uses forward slashes instead of backslashes.  This breaks
running of external commands because some external commands in Windows
treat any forward slash as a command line switch.

This change adds s:shellescape(), which wraps Vim's shellescape(), but
ensures 'noshellslash' is set first in Windows command prompt (not
Cygwin or msys) environments.  Having 'noshellslash' set when
shellescape() is called causes the string to be quoted, regardless of
whether there is whitespace or typical special characters, thus avoiding
the interpretation of the string as being command line switches.

Closes jamessan/vim-gnupg#41
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-09-29 19:48:18 -04:00
James McCoy
89253464f1
Use :language command to force C locale
In non-Windows environments, the gpg command is prepended with “LANG=C
LC_ALL=C” to ensure gpg's output is consistent to allow for parsing the
information.  However, that doesn't work in Windows and won't
necessarily work if we ever remove the code forcing use of /bin/sh.

Since Vim already knows how to influence the environment, use its
“:language message …” command to set/restore the locale before/after
running the gpg command.

Closes jamessan/vim-gnupg#45
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-09-29 19:32:19 -04:00
James McCoy
8394f2e1b5
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
2015-07-26 16:07:49 -04:00
James McCoy
ac5d94519e
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>
2015-07-16 23:13:12 -04:00
James McCoy
dd8e4adb4d
Silence "No matching autocommands" for TermChanged event
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-03-21 21:46:00 -04:00
James McCoy
553f9197d3 Document that GPGSystem always uses temp files
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-03-02 23:18:13 -05:00
James McCoy
671b84626e 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>
2015-02-06 09:53:09 -05:00
James McCoy
380f05d2e9 Trigger FileReadPost event after decrypting for :r
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-01-05 22:53:47 -05:00
James McCoy
cdf98c6af9 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>
2015-01-05 22:47:04 -05:00
James McCoy
30a49872ca Emit BufReadPre/FileReadPre when decrypting the file
Signed-off-by: James McCoy <vega.james@gmail.com>
2015-01-05 22:36:31 -05:00
James McCoy
3c01375c3b Don't change modified state of buffer for FileWriteCmd
Signed-off-by: James McCoy <vega.james@gmail.com>
2014-12-25 15:13:00 -05:00
James McCoy
9de82fa38a Emit FileWritePre/Post events when handling FileWriteCmd
Signed-off-by: James McCoy <vega.james@gmail.com>
2014-12-25 15:13:00 -05:00
Daniel Hahler
28c6e91593 Trigger BufWritePost event via BufWriteCmd/FileWriteCmd
Closes jamessan/vim-gnupg#23
Signed-off-by: James McCoy <vega.james@gmail.com>
2014-12-25 15:12:47 -05:00
James McCoy
20999789f8 Merge pull request #21 from tyll/menu
Add g:GPGRecipientsMenu
2014-11-20 23:52:31 -05:00
James McCoy
bd3ebdff6c 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>
2014-11-20 23:18:59 -05:00
Sebastian Neumann
d316155866 Refactor g:GPGRecipientsMenu to use list and rename to g:GPGPossibleRecipients
let g:GPGPossibleRecipients=[
    \"Example User <example@example.com>",
    \"Other User <otherexample@example.com>"
  \]
2014-10-29 16:53:59 +01:00
Till Maas
22f68e70cc 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>"
2014-10-09 16:55:42 +02:00
James McCoy
40cec4652c Put --homedir at the start of the command line
Closes jamessan/vim-gnupg#20
Signed-off-by: James McCoy <vega.james@gmail.com>
2014-08-10 18:48:00 -04:00
James McCoy
a1bc9f1ca0 Ensure b:GPGRecipients is initialized to a list value
Closes #18
Signed-off-by: James McCoy <vega.james@gmail.com>
2014-07-27 22:26:48 -04:00
nachoalonso
6e9f52a160 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>
2013-09-09 21:05:25 -04:00
James McCoy
15fd394fc5 Restore the :silent command when encrypting the buffer
This was lost in the refactor of external command handling, commit
7d102c843, and was causing an unnecessary "Press ENTER …" prompt to be
emitted whenever the buffer was written out.

Signed-off-by: James McCoy <vega.james@gmail.com>
2013-06-14 23:03:58 -04:00
James McCoy
27ea958f5b Allow definition of actions specific to GnuPG-managed buffers
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.

Closes jamessan/vim-gnupg#10

Signed-off-by: James McCoy <vega.james@gmail.com>
2013-04-23 22:32:13 -04:00
James McCoy
5ec1093bd7 Merge pull request #8 from Jonty/edit-recipients-on-new-file
Edit recipients when opening a new file
2013-02-22 12:42:21 -08:00
James McCoy
60091a5e1a Merge pull request #7 from Jonty/do-not-attempt-encryption-in-settings
Do not trigger encrypt on BufWrite etc in settings windows
2013-02-22 12:41:53 -08:00
Jonty Wareing
3e060c5ea0 Edit recipients when opening a new file
The previous behaviour of this plugin was to open the recipient pane
immediately after opening a new file with the correct extension. The
documentation states that this should still occur, so this commit
implements the behaviour in a slightly different manner than the old
plugin.
2013-02-22 19:59:12 +00:00
Jonty Wareing
2fb7599083 Do not trigger encrypt on BufWrite etc in settings
If a user :w's when in the options or recipient panes the global
bufwrite handlers will be called, triggering an attempt to encrypt the
file. The user will be dropped into the command line recipient adding
process, and the recipients listed in the buffer will be ignored.

This commit checks to see if a buffer is a child of another by looking
for the buffer local var containing the parent buffer name, and only
runs the encryption if it is not present.
2013-02-22 19:58:36 +00:00
James McCoy
57695361bb Document g:GPGFilePattern 2013-02-10 11:59:44 -05:00
James McCoy
6c758903e6 Merge pull request #4 from vaz/master 2013-02-10 11:57:54 -05:00
James McCoy
91442de02e Merge pull request #6 from matt-garman/patch-1
copy() g:GPGDefaultRecipients to b:GPGRecipients
2013-02-05 10:06:41 -08:00
matt-garman
faa3d652e3 Update plugin/gnupg.vim
Need to use copy() when setting b:GPGRecipients in GPGDecrypt(), otherwise the local variable will act as a reference to the global one.  The result will be that the global default recipient list will become a super-set of recipients as multiple gpg files are opened.
2013-02-05 11:52:40 -06:00
Vaz Allen
99ea6ced65 Add g:GPGFilePattern to allow custom target filename patterns.
This can be really handy when using vim as an external editor
for a program (via temporary files) that you'd like to be able to
encrypt based on the temp file's name (for example, when using
vim as an external editor for Notational Velocity).
2013-02-05 01:38:25 -08:00
James McCoy
dcb9d3764a Show all uids when disambiguating a key.
Previously, only a contiguous block of uids would be presented to the
user when trying to disambiguate a key.  This happened because a key may
have other fields interspersed among the uids, like UAT.

Signed-off-by: James McCoy <vega.james@gmail.com>
2013-01-27 20:59:18 -05:00
James McCoy
2f1d2c8244 Return a dictionary from GPGCheckRecipients
This is a step towards reporting keys that aren't valid for encryption
instead of just ignoring them.

Signed-off-by: James McCoy <vega.james@gmail.com>
2013-01-25 07:49:57 -05:00
James McCoy
7e6816802b Only define "unknown recipient" syntax if there are unknown recipients
Signed-off-by: James McCoy <vega.james@gmail.com>
2013-01-24 23:12:08 -05:00
James McCoy
68d35c30b2 Log v:shell_error after executing a shell command
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-12-21 21:16:38 -05:00
James McCoy
419695dd0f Run tty in a shell that has stdin attached to a tty
Using system('tty') will always report "not a tty", since the spawned shell
has stdin redirected.  In order to get an accurate value for $GPG_TTY when
it's not already set, read the output of the tty command using :!.

This requires a bit more setup/teardown to ensure the buffer and user's undo
state aren't affected, but it's the only way to accurately determine the
user's tty.

Closes: #1
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-28 22:53:07 -04:00
James McCoy
4a649a2dce Reduce "$GPG_TTY unset" message to one line and highlight as a warning.
It's possible that gpg will work fine without $GPG_TTY being set (e.g., when
using a GUI pinentry program).  Therefore, the message should be classified as
a warning, not an error.

Also, use a single :echom to ensure the user sees the entire message, not just
"gpg-agent might not work."

First part of GH #1

Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-28 22:39:46 -04:00
James McCoy
5c600287c7 Merge Markus' git repository so we have the original history 2012-10-26 17:36:59 -04:00
James McCoy
2844d06498 Ignore keys that aren't usable for encryption rather than just expired keys
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00
Thomas Arendsen Hein
6006af630b Do not echo debug messages when redirecting to a log file
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00
James McCoy
5489147a47 Use "silent doautocmd" to suppress annoying "No matching autocmds" message
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00
James McCoy
d973d05173 Change autocmd check to look for GnuPG group
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00
James McCoy
94c0a22b8a Ignore expired keys.
Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00
James McCoy
0e86346933 GPGFinishRecipientsBuffer: Use the GPG ID, if present, to avoid repeat prompts
Whenever GPGFinishRecipientsBuffer is called, the buffer is processed to
convert names to IDs.  However, this was ignoring any existing ID information
in the buffer.  This meant that if a person had multiple keys, the user would
be prompted to disambiguate the keys after every :GPGEditRecipients session.

Parsing the ID out of the recipients buffer avoids the unnecessary prompting.

Signed-off-by: James McCoy <vega.james@gmail.com>
2012-10-26 16:05:18 -04:00