From 419695dd0fa7350f47948cbc2e3f967814d4dc8e Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 28 Oct 2012 22:53:07 -0400 Subject: [PATCH] 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 --- plugin/gnupg.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index 69e6e51..dda9435 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -264,7 +264,22 @@ function s:GPGInit(bufread) " determine if gnupg can use the gpg-agent if (exists("$GPG_AGENT_INFO") && g:GPGUseAgent == 1) if (!exists("$GPG_TTY") && !has("gui_running")) - let $GPG_TTY = system("tty") + " 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