Skip to content

Commit 0ca4bae

Browse files
author
skywind3000
committed
take care of terminal cwd
1 parent 3cb5b33 commit 0ca4bae

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

plugin/asyncrun.vim

Lines changed: 31 additions & 4 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: 2021/02/14 19:14
6+
" Last Modified: 2021/03/28 22:06
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -1121,9 +1121,9 @@ endfunc
11211121

11221122

11231123
"----------------------------------------------------------------------
1124-
" open terminal in current window
1124+
" init terminal in current window
11251125
"----------------------------------------------------------------------
1126-
function! s:terminal_open(opts)
1126+
function! s:terminal_init(opts)
11271127
let command = a:opts.cmd
11281128
let hidden = get(a:opts, 'hidden', 0)
11291129
let shell = (has('nvim') == 0)? 1 : 0
@@ -1162,6 +1162,11 @@ function! s:terminal_open(opts)
11621162
if close
11631163
let opts.term_finish = 'close'
11641164
endif
1165+
if has('patch-8.1.0230')
1166+
if a:opts.cwd != ''
1167+
let opts.cwd = a:opts.cwd
1168+
endif
1169+
endif
11651170
try
11661171
let bid = term_start(command, opts)
11671172
catch /^.*/
@@ -1173,6 +1178,9 @@ function! s:terminal_open(opts)
11731178
else
11741179
let opts = {'stoponexit':'term'}
11751180
let opts.exit_cb = function('s:terminal_exit')
1181+
if a:opts.cwd != ''
1182+
let opts.cwd = a:opts.cwd
1183+
endif
11761184
let jid = job_start(command, opts)
11771185
let bid = -1
11781186
let success = (job_status(jid) != 'fail')? 1 : 0
@@ -1181,6 +1189,9 @@ function! s:terminal_open(opts)
11811189
else
11821190
let opts = {}
11831191
let opts.on_exit = function('s:terminal_exit')
1192+
if a:opts.cwd != ''
1193+
let opts.cwd = a:opts.cwd
1194+
endif
11841195
if pos != 'hide'
11851196
try
11861197
enew
@@ -1229,6 +1240,22 @@ function! s:terminal_open(opts)
12291240
endfunc
12301241

12311242

1243+
"----------------------------------------------------------------------
1244+
" init terminal in current window
1245+
"----------------------------------------------------------------------
1246+
function! s:terminal_open(opts)
1247+
let previous = getcwd()
1248+
if a:opts.cwd != ''
1249+
call s:chdir(a:opts.cwd)
1250+
endif
1251+
let hr = s:terminal_init(a:opts)
1252+
if a:opts.cwd != ''
1253+
call s:chdir(previous)
1254+
endif
1255+
return hr
1256+
endfunc
1257+
1258+
12321259
"----------------------------------------------------------------------
12331260
" exit callback
12341261
"----------------------------------------------------------------------
@@ -1886,7 +1913,7 @@ endfunc
18861913
" asyncrun - version
18871914
"----------------------------------------------------------------------
18881915
function! asyncrun#version()
1889-
return '2.8.4'
1916+
return '2.8.5'
18901917
endfunc
18911918

18921919

0 commit comments

Comments
 (0)