Skip to content

Commit 90d3a0f

Browse files
author
skywind3000
committed
2.4.6: new macros for -program=wsl: WSL_FILEPATH, WSL_FILEDIR, ...
1 parent db7e7df commit 90d3a0f

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

plugin/asyncrun.vim

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: skywind3000 (at) gmail.com, 2016, 2017, 2018, 2019, 2020
44
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
55
"
6-
" Last Modified: 2020/02/17 21:36
6+
" Last Modified: 2020/02/18 21:11
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -1066,6 +1066,26 @@ function! asyncrun#path_join(home, name)
10661066
return s:path_join(a:home, a:name)
10671067
endfunc
10681068

1069+
" change to unix
1070+
function! asyncrun#path_win2unix(winpath, prefix)
1071+
let prefix = a:prefix
1072+
let path = a:winpath
1073+
if path =~ '^\a:[/\\]'
1074+
let drive = tolower(strpart(path, 0, 1))
1075+
let name = strpart(path, 3)
1076+
let p = s:path_join(prefix, drive)
1077+
let p = s:path_join(p, name)
1078+
return tr(p, '\', '/')
1079+
elseif path =~ '^[/\\]'
1080+
let drive = tolower(strpart(getcwd(), 0, 1))
1081+
let name = strpart(path, 1)
1082+
let p = s:path_join(prefix, drive)
1083+
let p = s:path_join(p, name)
1084+
return tr(p, '\', '/')
1085+
else
1086+
return tr(a:winpath, '\', '/')
1087+
endif
1088+
endfunc
10691089

10701090

10711091
"----------------------------------------------------------------------
@@ -1591,11 +1611,24 @@ function! asyncrun#run(bang, opts, args, ...)
15911611
let l:macros['<cwd>'] = l:macros['VIM_CWD']
15921612
endif
15931613

1614+
" windows can use $(WSL_XXX)
1615+
if s:asyncrun_windows != 0
1616+
let wslnames = ['FILEPATH', 'FILENAME', 'FILEDIR', 'FILENOEXT']
1617+
let wslnames += ['PATHNOEXT', 'FILEEXT', 'FILETYPE', 'RELDIR']
1618+
let wslnames += ['RELNAME', 'CFILE', 'ROOT', 'HOME', 'CWD']
1619+
for name in wslnames
1620+
let src = l:macros['VIM_' . name]
1621+
let l:macros['WSL_' . name] = asyncrun#path_win2unix(src, '/mnt')
1622+
endfor
1623+
endif
1624+
15941625
" replace macros and setup environment variables
15951626
for [l:key, l:val] in items(l:macros)
15961627
let l:replace = (l:key[0] != '<')? '$('.l:key.')' : l:key
15971628
if l:key[0] != '<'
1598-
exec 'let $'.l:key.' = l:val'
1629+
if strpart(l:key, 0, 4) != 'WSL_'
1630+
exec 'let $'.l:key.' = l:val'
1631+
endif
15991632
endif
16001633
let l:command = s:StringReplace(l:command, l:replace, l:val)
16011634
let l:opts.text = s:StringReplace(l:opts.text, l:replace, l:val)
@@ -1659,7 +1692,7 @@ endfunc
16591692
" asyncrun - version
16601693
"----------------------------------------------------------------------
16611694
function! asyncrun#version()
1662-
return '2.4.5'
1695+
return '2.4.6'
16631696
endfunc
16641697

16651698

0 commit comments

Comments
 (0)