escape all command arguments for shell
This commit is contained in:
parent
1e2ba90f70
commit
3162cbdaac
|
@ -102,6 +102,18 @@ let s:VERSION = '4.0.1'
|
||||||
return expand("%:p")
|
return expand("%:p")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:EscapeArg(arg)
|
||||||
|
return substitute(shellescape(a:arg), '!', '\\!', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:JoinArgs(args)
|
||||||
|
let safeArgs = []
|
||||||
|
for arg in a:args
|
||||||
|
let safeArgs = safeArgs + [s:EscapeArg(arg)]
|
||||||
|
endfor
|
||||||
|
return join(safeArgs, ' ')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Api(targetFile, time, is_write, last)
|
function! s:Api(targetFile, time, is_write, last)
|
||||||
let targetFile = a:targetFile
|
let targetFile = a:targetFile
|
||||||
if targetFile == ''
|
if targetFile == ''
|
||||||
|
@ -114,17 +126,17 @@ let s:VERSION = '4.0.1'
|
||||||
let python_bin = 'pythonw'
|
let python_bin = 'pythonw'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let cmd = [python_bin, '-W', 'ignore', '"' . s:cli_location . '"']
|
let cmd = [python_bin, '-W', 'ignore', s:cli_location]
|
||||||
let cmd = cmd + ['--file', shellescape(targetFile)]
|
let cmd = cmd + ['--file', targetFile]
|
||||||
let cmd = cmd + ['--plugin', shellescape(printf('vim/%d vim-wakatime/%s', v:version, s:VERSION))]
|
let cmd = cmd + ['--plugin', printf('vim/%d vim-wakatime/%s', v:version, s:VERSION)]
|
||||||
if a:is_write
|
if a:is_write
|
||||||
let cmd = cmd + ['--write']
|
let cmd = cmd + ['--write']
|
||||||
endif
|
endif
|
||||||
"let cmd = cmd + ['--verbose']
|
"let cmd = cmd + ['--verbose']
|
||||||
if has('win32') || has('win64')
|
if has('win32') || has('win64')
|
||||||
exec 'silent !start /min cmd /c "' . join(cmd, ' ') . '"'
|
exec 'silent !start /min cmd /c "' . s:JoinArgs(cmd) . '"'
|
||||||
else
|
else
|
||||||
exec 'silent !' . join(cmd, ' ') . ' &'
|
exec 'silent !' . s:JoinArgs(cmd) . ' &'
|
||||||
endif
|
endif
|
||||||
call s:SetLastHeartbeat(a:time, a:time, targetFile)
|
call s:SetLastHeartbeat(a:time, a:time, targetFile)
|
||||||
endif
|
endif
|
||||||
|
|
Loading…
Reference in New Issue