From c2c9720584f418c0012c9caa86529bf8167edcb5 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 23 Aug 2019 18:57:20 -0400 Subject: [PATCH 1/2] 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 --- autoload/gnupg.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index 5d43bdf..87062f3 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -1,5 +1,5 @@ " Name: autoload/gnupg.vim -" Last Change: 2019 Feb 11 +" Last Change: 2019 Aug 23 " Maintainer: James McCoy " Original Author: Markus Braun " Summary: Vim plugin for transparent editing of gpg encrypted files. @@ -217,7 +217,7 @@ function gnupg#init(bufread) set undolevels=-1 silent read !tty let $GPG_TTY = getline('.') - silent delete + silent '[,']delete _ let [&l:modified, &undolevels] = [mod, levels] " redraw is needed since we're using silent to run !tty, c.f. :help :! redraw! From 5001a8b45dcb50b7c782e216cfc3d353ed0249a0 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 23 Aug 2019 19:02:29 -0400 Subject: [PATCH 2/2] Do not try to run tty command if it doesn't exist Signed-off-by: James McCoy --- autoload/gnupg.vim | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/autoload/gnupg.vim b/autoload/gnupg.vim index 87062f3..9a91ed0 100644 --- a/autoload/gnupg.vim +++ b/autoload/gnupg.vim @@ -213,18 +213,20 @@ function gnupg#init(bufread) " 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) + if executable('tty') + 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! + endif + if v:shell_error || !exists("$GPG_TTY") let $GPG_TTY = "" echohl GPGWarning - echom "$GPG_TTY is not set and the `tty` command failed! gpg-agent might not work." + echom "$GPG_TTY is not set and the `tty` command failed/doesn't exist! gpg-agent might not work." echohl None endif endif