mirror of
https://github.com/Ascyii/vim-gnupg.git
synced 2026-01-01 06:14:24 -05:00
Make gnupg.vim working with cmd under windows.
This commit is contained in:
@@ -114,11 +114,27 @@ fun s:GPGInit()
|
|||||||
let s:GPGCommand="LANG=C gpg --no-use-agent"
|
let s:GPGCommand="LANG=C gpg --no-use-agent"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" setup shell environment for unix and windows
|
||||||
|
let s:shellredirsave=&shellredir
|
||||||
|
let s:shellsave=&shell
|
||||||
|
if (match(&shell,"cmd.exe"))
|
||||||
|
" windows specific settings
|
||||||
|
let s:shellredir = '>%s'
|
||||||
|
let s:shell = &shell
|
||||||
|
let s:redirnull = '2>nul'
|
||||||
|
else
|
||||||
|
" unix specific settings
|
||||||
|
let s:shellredir = &shellredir
|
||||||
|
let s:shell = 'sh'
|
||||||
|
let s:redirnull ='2>/dev/null'
|
||||||
|
endi
|
||||||
|
|
||||||
" find the supported algorithms
|
" find the supported algorithms
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
let output=system(s:GPGCommand . " --version")
|
let output=system(s:GPGCommand . " --version")
|
||||||
let &sh=shsave
|
let &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
|
|
||||||
let s:GPGPubkey=substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGPubkey=substitute(output, ".*Pubkey: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
let s:GPGCipher=substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "")
|
let s:GPGCipher=substitute(output, ".*Cipher: \\(.\\{-}\\)\n.*", "\\1", "")
|
||||||
@@ -140,10 +156,11 @@ fun s:GPGDecrypt()
|
|||||||
let b:GPGOptions=""
|
let b:GPGOptions=""
|
||||||
|
|
||||||
" find the recipients of the file
|
" find the recipients of the file
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
let output=system(s:GPGCommand . " --decrypt --dry-run --batch " . filename)
|
let output=system(s:GPGCommand . " --decrypt --dry-run --batch " . filename)
|
||||||
let &sh=shsave
|
let &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
|
|
||||||
" check if the file is symmetric/asymmetric encrypted
|
" check if the file is symmetric/asymmetric encrypted
|
||||||
if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0)
|
if (match(output, "gpg: [^ ]\\+ encrypted data") >= 0)
|
||||||
@@ -189,11 +206,12 @@ fun s:GPGDecrypt()
|
|||||||
|
|
||||||
" finally decrypt the buffer content
|
" finally decrypt the buffer content
|
||||||
" since even with the --quiet option passphrase typos will be reported,
|
" since even with the --quiet option passphrase typos will be reported,
|
||||||
" we must redirect stderr (using sh temporarily)
|
" we must redirect stderr (using shell temporarily)
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
exec "'[,']!" . s:GPGCommand . " --quiet --decrypt 2>/dev/null"
|
exec "'[,']!" . s:GPGCommand . " --quiet --decrypt " . s:redirnull
|
||||||
let &sh=shsave
|
let &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
if (v:shell_error) " message could not be decrypted
|
if (v:shell_error) " message could not be decrypted
|
||||||
silent u
|
silent u
|
||||||
echohl GPGError
|
echohl GPGError
|
||||||
@@ -254,10 +272,11 @@ fun s:GPGEncrypt()
|
|||||||
endi
|
endi
|
||||||
|
|
||||||
" encrypt the buffer
|
" encrypt the buffer
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
silent exec "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . recipients . " 2>/dev/null"
|
silent exec "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . recipients . " " . s:redirnull
|
||||||
let &sh=shsave
|
let &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
if (v:shell_error) " message could not be encrypted
|
if (v:shell_error) " message could not be encrypted
|
||||||
silent u
|
silent u
|
||||||
echohl GPGError
|
echohl GPGError
|
||||||
@@ -596,10 +615,11 @@ endf
|
|||||||
" Returns: ID for the given name
|
" Returns: ID for the given name
|
||||||
fun s:GPGNameToID(name)
|
fun s:GPGNameToID(name)
|
||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
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 &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
let pub_seen=0
|
let pub_seen=0
|
||||||
@@ -659,10 +679,11 @@ fun s:GPGIDToName(identity)
|
|||||||
" TODO is the encryption subkey really unique?
|
" TODO is the encryption subkey really unique?
|
||||||
|
|
||||||
" ask gpg for the id for a name
|
" ask gpg for the id for a name
|
||||||
let shsave=&sh
|
let &shellredir=s:shellredir
|
||||||
let &sh='sh'
|
let &shell=s:shell
|
||||||
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 &shellredir=s:shellredir
|
||||||
|
let &shell=s:shellsave
|
||||||
|
|
||||||
" parse the output of gpg
|
" parse the output of gpg
|
||||||
let pub_seen=0
|
let pub_seen=0
|
||||||
|
|||||||
Reference in New Issue
Block a user