Skip to content

Commit

Permalink
Escape command in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
djmoch committed Dec 8, 2016
1 parent d043ec6 commit 02c246e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugin/makejob.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ function! s:Expand(input)
return join(l:expanded_input)
endfunction

" Credit to Tim Pope for the magic here
function! s:Escape(str)
if has('win32') || has('win64')
if &shellxquote ==# '"'
return '"' . substitute(a:str, '"', '""', 'g') . '"'
else
let l:esc = exists('+shellxescape') ? &shellxescape : '"&|<>()@^'
return &shellxquote .
\ substitute(a:str, '['.l:esc.']', '^&', 'g') .
\ get({'(': ')', '"(': ')"'}, &shellxquote, &shellxquote)
endif
else
return a:str
endif
endfunction

function! s:MakeJob(grep, lmake, grepadd, bang, ...)
let l:make = a:grep ? s:Expand(&grepprg) : s:Expand(&makeprg)
let l:prog = split(l:make)[0]
Expand Down Expand Up @@ -119,9 +135,7 @@ function! s:MakeJob(grep, lmake, grepadd, bang, ...)
let l:make = l:make.' '.l:arg
endif

if a:grep
let l:make = [&shell, &shellcmdflag, l:make]
endif
let l:make = [&shell, &shellcmdflag, s:Escape(l:make)]
endif

let l:opts = { 'close_cb' : function('s:JobHandler'),
Expand Down

0 comments on commit 02c246e

Please sign in to comment.