Skip to content

Commit

Permalink
Pin default shell to cmd.exe on windows. Fix path seprator for windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
ysl2 committed Jan 16, 2023
1 parent 787be15 commit f7a7851
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugin/mdip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ function! s:SaveFileTMPLinux(imgdir, tmpname) abort
endfunction

function! s:SaveFileTMPWin32(imgdir, tmpname) abort
let shell_bak = &shell
let shellcmdflag_bak = &shellcmdflag
let &shell = 'cmd.exe'
let &shellcmdflag = '/s /c'

let tmpfile = a:imgdir . '\' . a:tmpname . '.png'
let tmpfile = substitute(tmpfile, '\\ ', ' ', 'g')

Expand All @@ -99,6 +104,10 @@ function! s:SaveFileTMPWin32(imgdir, tmpname) abort
let clip_command = "powershell -nologo -noprofile -noninteractive -sta \"".clip_command. "\""

silent call system(clip_command)

let &shell = shell_bak
let &shellcmdflag = shellcmdflag_bak

if v:shell_error == 1
return 1
else
Expand Down Expand Up @@ -194,7 +203,7 @@ function! g:LatexPasteImage(relpath)
endfunction

function! g:EmptyPasteImage(relpath)
execute "normal! i" . a:relpath
execute "normal! i" . a:relpath
endfunction

let g:PasteImageFunction = 'g:MarkdownPasteImage'
Expand Down Expand Up @@ -228,7 +237,8 @@ function! mdip#MarkdownClipboardImage()
else
" let relpath = s:SaveNewFile(g:mdip_imgdir, tmpfile)
let extension = split(tmpfile, '\.')[-1]
let relpath = g:mdip_imgdir_intext . '/' . g:mdip_tmpname . '.' . extension
let sep = has('win32') ? '\' : '/'
let relpath = g:mdip_imgdir_intext . sep . g:mdip_tmpname . '.' . extension
if call(get(g:, 'PasteImageFunction'), [relpath])
return
endif
Expand Down

1 comment on commit f7a7851

@Konfekt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this recurs and has been battle-tested maybe, it's safer to copy

Please sign in to comment.