Introduced variable GPGUseAgent
Selectively enable usage of gpg-agent.
This commit is contained in:
parent
167ef9a4f3
commit
a14b9fe592
@ -42,6 +42,10 @@
|
|||||||
" :GPGViewRecipients
|
" :GPGViewRecipients
|
||||||
" Prints the list of options.
|
" Prints the list of options.
|
||||||
"
|
"
|
||||||
|
" Variables:
|
||||||
|
" GPGUseAgent
|
||||||
|
" If set to 1 a possible available gpg-agent is used. Defaults to 0.
|
||||||
|
"
|
||||||
" Credits:
|
" Credits:
|
||||||
" Mathieu Clabaut for inspirations through his vimspell.vim script.
|
" Mathieu Clabaut for inspirations through his vimspell.vim script.
|
||||||
" Section: Plugin header {{{1
|
" Section: Plugin header {{{1
|
||||||
@ -92,17 +96,22 @@ highlight default GPGHighlightUnknownRecipient term=reverse ctermfg=Red cterm=un
|
|||||||
" initialize the plugin
|
" initialize the plugin
|
||||||
"
|
"
|
||||||
fun s:GPGInit()
|
fun s:GPGInit()
|
||||||
|
" check if gpg-agent is allowed
|
||||||
|
if (!exists("GPGUseAgent"))
|
||||||
|
let GPGUseAgent = 0
|
||||||
|
endif
|
||||||
|
|
||||||
" determine if gnupg can use the gpg-agent
|
" determine if gnupg can use the gpg-agent
|
||||||
if (exists("$GPG_AGENT_INFO"))
|
if (exists("$GPG_AGENT_INFO") && GPGUseAgent == 1)
|
||||||
let s:gpgcommand="LANG=C gpg --use-agent"
|
let s:GPGCommand="LANG=C gpg --use-agent"
|
||||||
else
|
else
|
||||||
let s:gpgcommand="LANG=C gpg --no-use-agent"
|
let s:GPGCommand="LANG=C gpg --no-use-agent"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" find the supported algorithms
|
" find the supported algorithms
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
let output=system(s:gpgcommand . " --version")
|
let output=system(s:GPGCommand . " --version")
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
|
|
||||||
let s:GPGPubkey=substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGPubkey=substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
@ -127,7 +136,7 @@ fun s:GPGDecrypt()
|
|||||||
" find the recipients of the file
|
" find the recipients of the file
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
let output=system(s:gpgcommand . " --decrypt --dry-run --batch " . filename)
|
let output=system(s:GPGCommand . " --decrypt --dry-run --batch " . filename)
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
|
|
||||||
" check if the file is symmetric/asymmetric encrypted
|
" check if the file is symmetric/asymmetric encrypted
|
||||||
@ -177,7 +186,7 @@ fun s:GPGDecrypt()
|
|||||||
" we must redirect stderr (using sh temporarily)
|
" we must redirect stderr (using sh temporarily)
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
exec "'[,']!" . s:gpgcommand . " --quiet --decrypt 2>/dev/null"
|
exec "'[,']!" . s:GPGCommand . " --quiet --decrypt 2>/dev/null"
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
if (v:shell_error) " message could not be decrypted
|
if (v:shell_error) " message could not be decrypted
|
||||||
silent u
|
silent u
|
||||||
@ -241,7 +250,7 @@ fun s:GPGEncrypt()
|
|||||||
" encrypt the buffer
|
" encrypt the buffer
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
silent exec "'[,']!" . s:gpgcommand . " --quiet --no-encrypt-to " . options . recipients . " 2>/dev/null"
|
silent exec "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . recipients . " 2>/dev/null"
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
if (v:shell_error) " message could not be encrypted
|
if (v:shell_error) " message could not be encrypted
|
||||||
silent u
|
silent u
|
||||||
@ -583,7 +592,7 @@ fun s:GPGNameToID(name)
|
|||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
let output=system(s:gpgcommand . " --quiet --with-colons --fixed-list-mode --list-keys \"" . a:name . "\"")
|
let output=system(s:GPGCommand . " --quiet --with-colons --fixed-list-mode --list-keys \"" . a:name . "\"")
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
@ -646,7 +655,7 @@ fun s:GPGIDToName(identity)
|
|||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
let shsave=&sh
|
let shsave=&sh
|
||||||
let &sh='sh'
|
let &sh='sh'
|
||||||
let output=system(s:gpgcommand . " --quiet --with-colons --fixed-list-mode --list-keys " . a:identity )
|
let output=system(s:GPGCommand . " --quiet --with-colons --fixed-list-mode --list-keys " . a:identity )
|
||||||
let &sh=shsave
|
let &sh=shsave
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
|
Loading…
x
Reference in New Issue
Block a user