Skip to content

Commit 5e90d22

Browse files
committed
Handle exit callback
We can also freeze the state to avoid tpipeline using dead channels in a fatal scenario.
1 parent c7104e6 commit 5e90d22

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

autoload/tpipeline.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ if !has('nvim')
22
import autoload 'tpipeline/parse.vim'
33
endif
44

5+
let s:exit_code = -1
6+
57
func tpipeline#get_filepath()
68
" e.g. /tmp/tmux-1000/default-$0-vimbridge
79
let tmux = $TMUX
@@ -140,6 +142,16 @@ func tpipeline#initialize()
140142
augroup END
141143
endfunc
142144

145+
func tpipeline#on_exit(job, code, t)
146+
call tpipeline#state#freeze()
147+
let s:exit_code = a:code
148+
endfunc
149+
150+
func tpipeline#exit_cb(job, code)
151+
call tpipeline#state#freeze()
152+
let s:exit_code = a:code
153+
endfunc
154+
143155
func tpipeline#fork_job()
144156
if g:tpipeline_restore
145157
let s:restore_left = systemlist("sh -c 'echo \"\"; tmux display-message -p \"#{status-left}\"'")[-1]
@@ -171,10 +183,11 @@ func tpipeline#fork_job()
171183

172184
let command = ['bash', '-c', script]
173185
if s:is_nvim
174-
let s:job = jobstart(command)
186+
let options = #{on_exit: function('tpipeline#on_exit')}
187+
let s:job = jobstart(command, options)
175188
let s:channel = s:job
176189
else
177-
let options = #{noblock: 1}
190+
let options = #{noblock: 1, exit_cb: function('tpipeline#exit_cb')}
178191
let s:job = job_start(command, options)
179192
let s:channel = job_getchannel(s:job)
180193
endif
@@ -320,6 +333,9 @@ func tpipeline#job_state()
320333
else
321334
let res = job_status(s:job)
322335
endif
336+
if s:exit_code > -1
337+
let res .= printf(" (exit code %d)", s:exit_code)
338+
endif
323339

324340
return res
325341
endfunc

0 commit comments

Comments
 (0)