3
3
" Maintainer: skywind3000 (at) gmail.com, 2016, 2017, 2018, 2019, 2020
4
4
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
5
5
"
6
- " Last Modified: 2021/02/14 19:14
6
+ " Last Modified: 2021/03/28 22:06
7
7
"
8
8
" Run shell command in background and output to quickfix:
9
9
" :AsyncRun[!] [options] {cmd} ...
@@ -1121,9 +1121,9 @@ endfunc
1121
1121
1122
1122
1123
1123
" ----------------------------------------------------------------------
1124
- " open terminal in current window
1124
+ " init terminal in current window
1125
1125
" ----------------------------------------------------------------------
1126
- function ! s: terminal_open (opts)
1126
+ function ! s: terminal_init (opts)
1127
1127
let command = a: opts .cmd
1128
1128
let hidden = get (a: opts , ' hidden' , 0 )
1129
1129
let shell = (has (' nvim' ) == 0 )? 1 : 0
@@ -1162,6 +1162,11 @@ function! s:terminal_open(opts)
1162
1162
if close
1163
1163
let opts.term_finish = ' close'
1164
1164
endif
1165
+ if has (' patch-8.1.0230' )
1166
+ if a: opts .cwd != ' '
1167
+ let opts.cwd = a: opts .cwd
1168
+ endif
1169
+ endif
1165
1170
try
1166
1171
let bid = term_start (command , opts)
1167
1172
catch /^.*/
@@ -1173,6 +1178,9 @@ function! s:terminal_open(opts)
1173
1178
else
1174
1179
let opts = {' stoponexit' :' term' }
1175
1180
let opts.exit_cb = function (' s:terminal_exit' )
1181
+ if a: opts .cwd != ' '
1182
+ let opts.cwd = a: opts .cwd
1183
+ endif
1176
1184
let jid = job_start (command , opts)
1177
1185
let bid = -1
1178
1186
let success = (job_status (jid) != ' fail' )? 1 : 0
@@ -1181,6 +1189,9 @@ function! s:terminal_open(opts)
1181
1189
else
1182
1190
let opts = {}
1183
1191
let opts.on_exit = function (' s:terminal_exit' )
1192
+ if a: opts .cwd != ' '
1193
+ let opts.cwd = a: opts .cwd
1194
+ endif
1184
1195
if pos != ' hide'
1185
1196
try
1186
1197
enew
@@ -1229,6 +1240,22 @@ function! s:terminal_open(opts)
1229
1240
endfunc
1230
1241
1231
1242
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
+
1232
1259
" ----------------------------------------------------------------------
1233
1260
" exit callback
1234
1261
" ----------------------------------------------------------------------
@@ -1886,7 +1913,7 @@ endfunc
1886
1913
" asyncrun - version
1887
1914
" ----------------------------------------------------------------------
1888
1915
function ! asyncrun#version ()
1889
- return ' 2.8.4 '
1916
+ return ' 2.8.5 '
1890
1917
endfunc
1891
1918
1892
1919
0 commit comments