Skip to content

Commit 527fae3

Browse files
author
skywind3000
committed
improve error handling
1 parent 0ca4bae commit 527fae3

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

plugin/asyncrun.vim

Lines changed: 12 additions & 10 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/03/28 22:06
6+
" Last Modified: 2021/03/29 08:58
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -1129,6 +1129,8 @@ function! s:terminal_init(opts)
11291129
let shell = (has('nvim') == 0)? 1 : 0
11301130
let pos = get(a:opts, 'pos', 'bottom')
11311131
let pos = (pos == 'background')? 'hide' : pos
1132+
let cwd = a:opts.cwd
1133+
let cwd = (cwd != '' && isdirectory(cwd))? cwd : ''
11321134
if get(a:opts, 'safe', get(g:, 'asyncrun_term_safe', 0)) != 0
11331135
let command = s:ScriptWrite(command, 0)
11341136
if stridx(command, ' ') >= 0
@@ -1163,8 +1165,8 @@ function! s:terminal_init(opts)
11631165
let opts.term_finish = 'close'
11641166
endif
11651167
if has('patch-8.1.0230')
1166-
if a:opts.cwd != ''
1167-
let opts.cwd = a:opts.cwd
1168+
if cwd != ''
1169+
let opts.cwd = cwd
11681170
endif
11691171
endif
11701172
try
@@ -1178,8 +1180,8 @@ function! s:terminal_init(opts)
11781180
else
11791181
let opts = {'stoponexit':'term'}
11801182
let opts.exit_cb = function('s:terminal_exit')
1181-
if a:opts.cwd != ''
1182-
let opts.cwd = a:opts.cwd
1183+
if cwd != ''
1184+
let opts.cwd = cwd
11831185
endif
11841186
let jid = job_start(command, opts)
11851187
let bid = -1
@@ -1189,8 +1191,8 @@ function! s:terminal_init(opts)
11891191
else
11901192
let opts = {}
11911193
let opts.on_exit = function('s:terminal_exit')
1192-
if a:opts.cwd != ''
1193-
let opts.cwd = a:opts.cwd
1194+
if cwd != ''
1195+
let opts.cwd = cwd
11941196
endif
11951197
if pos != 'hide'
11961198
try
@@ -1246,11 +1248,11 @@ endfunc
12461248
function! s:terminal_open(opts)
12471249
let previous = getcwd()
12481250
if a:opts.cwd != ''
1249-
call s:chdir(a:opts.cwd)
1251+
silent! call s:chdir(a:opts.cwd)
12501252
endif
12511253
let hr = s:terminal_init(a:opts)
12521254
if a:opts.cwd != ''
1253-
call s:chdir(previous)
1255+
silent! call s:chdir(previous)
12541256
endif
12551257
return hr
12561258
endfunc
@@ -1913,7 +1915,7 @@ endfunc
19131915
" asyncrun - version
19141916
"----------------------------------------------------------------------
19151917
function! asyncrun#version()
1916-
return '2.8.5'
1918+
return '2.8.6'
19171919
endfunc
19181920

19191921

0 commit comments

Comments
 (0)