how do I determine the status of a process within a terminal tab?

41 views
Skip to first unread message

surge

unread,
Jan 3, 2020, 4:42:23 PM1/3/20
to vim_use
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 an entry similar to:

 7 %aF "!echo "test" [finished]" line 1

Question: is there a vimscript 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. Namely,

before changes can be made to a terminal buffer, the 'modifiable' option must be set. This is only possible when the job has finished:

So, is examining the modifiable option the best way to determine if a shell process has finished? What if I wanted to examine the exis status?

Yegappan Lakshmanan

unread,
Jan 3, 2020, 8:57:37 PM1/3/20
to vim...@googlegroups.com
Hi,

On Sat, Jan 4, 2020 at 3:12 AM surge <ger...@gmail.com> wrote:
>
> 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 an entry similar to:
>
> 7 %aF "!echo "test" [finished]" line 1
>
> Question: is there a vimscript function that could return such extended information about a buffer?
>

Yes. You can use the term_getstatus() function to get the status of
the terminal.
You can use the getbufinfo(), term_getjob() and job_info() functions to get
additional details about the job running in a terminal window.

Example (assuming the buffer number for the terminal is 2):
:echo term_getjob(2)->job_info()
:echo term_getstatus(2)
:echo term_getjob(2)->job_status()
:echo getbufinfo(2)[0].name

- Yegappan

surge

unread,
Jan 3, 2020, 11:57:17 PM1/3/20
to vim_use
Thank you so much, Yegappan. That's exactly what I needed.
Reply all
Reply to author
Forward
0 new messages