Reputation: 326
The :ls
command in Vim output the current buffers in Vim. If one of the buffers is a terminal, there are some useful flags to examine there. For example, if the command was:
term echo "test"
:ls
will contain this as one of the entries:
...
7 %aF "!echo "test" [finished]" line 1
...
Is there a vim function that could return such extended information about a buffer? :help terminal
suggests that if modifiable
option is off
, the job had to have finished.
before changes can be made to a terminal buffer, the 'modifiable' option must be set. This is only possible when the job has finished:
To rephrase my question, how do I know the status of a shell process started with the term
command?
Upvotes: 4
Views: 1215
Reputation: 15091
Terminal process is always bound to a buffer, not a tab. In Vim there exists a function term_getstatus()
; in Neovim it's jobwait()
.
Here is a generic function from my config:
function! term#running(buf)
return getbufvar(a:buf, '&buftype') !=# 'terminal' ? 0 :
\ has('terminal') ? term_getstatus(a:buf) =~# 'running' :
\ has('nvim') ? jobwait([getbufvar(a:buf, '&channel')], 0)[0] == -1 :
\ 0
endfunction
Upvotes: 4