Skip to content

Commit

Permalink
Fix Windows batch file format (#755)
Browse files Browse the repository at this point in the history
`writefile()` always output LF without CR each lines.
But batch file on Windows needs CR and LF, at end of lines.

And if the path of home directory contains non-ASCII
characters like Japanese username (e.g. `C:\Users\太郎`),
batch file without CR can't be executed correctly.
  • Loading branch information
watagashi authored and junegunn committed May 12, 2018
1 parent e6a775e commit fef4e43
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ function! s:bang(cmd, ...)
let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd
if s:is_win
let batchfile = tempname().'.bat'
call writefile(['@echo off', cmd], batchfile)
call writefile(["@echo off\r", cmd . "\r"], batchfile)
let cmd = batchfile
endif
let g:_plug_bang = (s:is_win && has('gui_running') ? 'silent ' : '').'!'.escape(cmd, '#!%')
Expand Down Expand Up @@ -1196,7 +1196,7 @@ function! s:spawn(name, cmd, opts)
let s:jobs[a:name] = job
let cmd = has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd
if !empty(job.batchfile)
call writefile(['@echo off', cmd], job.batchfile)
call writefile(["@echo off\r", cmd . "\r"], job.batchfile)
let cmd = job.batchfile
endif
let argv = add(s:is_win ? ['cmd', '/c'] : ['sh', '-c'], cmd)
Expand Down Expand Up @@ -2023,7 +2023,7 @@ function! s:system(cmd, ...)
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
if s:is_win
let batchfile = tempname().'.bat'
call writefile(['@echo off', cmd], batchfile)
call writefile(["@echo off\r", cmd . "\r"], batchfile)
let cmd = batchfile
endif
return system(s:is_win ? '('.cmd.')' : cmd)
Expand Down Expand Up @@ -2357,7 +2357,7 @@ function! s:preview_commit()
let cmd = 'cd '.s:shellesc(g:plugs[name].dir).' && git show --no-color --pretty=medium '.sha
if s:is_win
let batchfile = tempname().'.bat'
call writefile(['@echo off', cmd], batchfile)
call writefile(["@echo off\r", cmd . "\r"], batchfile)
let cmd = batchfile
endif
execute 'silent %!' cmd
Expand Down

0 comments on commit fef4e43

Please sign in to comment.