Skip to content

Commit

Permalink
util: handle joining args when shell is powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed Jun 8, 2022
1 parent d34c629 commit 34aeb1d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,21 @@ endfunction
" Shelljoin returns a shell-safe string representation of arglist. The
" {special} argument of shellescape() may optionally be passed.
function! go#util#Shelljoin(arglist, ...) abort
" Preserve original shell. This needs to be kept in sync with how s:system
" sets shell.
let l:shell = &shell

try
if !go#util#IsWin() && executable('/bin/sh')
set shell=/bin/sh
endif

if go#util#IsWin()
if executable($COMSPEC)
let &shell = $COMSPEC
endif
endif

let ssl_save = &shellslash
set noshellslash
if a:0
Expand All @@ -307,30 +321,22 @@ function! go#util#Shelljoin(arglist, ...) abort

return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ')
finally
" Restore original values
let &shellslash = ssl_save
let &shell = l:shell
endtry
endfunction

fu! go#util#Shellescape(arg)
try
let ssl_save = &shellslash
set noshellslash
return shellescape(a:arg)
finally
let &shellslash = ssl_save
endtry
endf

" Shelllist returns a shell-safe representation of the items in the given
" arglist. The {special} argument of shellescape() may optionally be passed.
function! go#util#Shelllist(arglist, ...) abort
try
let ssl_save = &shellslash
set noshellslash
if a:0
return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')')
return map(copy(a:arglist), 'go#util#Shelljoin(v:val, ' . a:1 . ')')
endif
return map(copy(a:arglist), 'shellescape(v:val)')
return map(copy(a:arglist), 'go#util#Shelljoin(v:val)')
finally
let &shellslash = ssl_save
endtry
Expand Down

0 comments on commit 34aeb1d

Please sign in to comment.