diff options
author | Gregory Anders <greg@gpanders.com> | 2021-08-20 14:58:28 -0600 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2023-08-10 09:06:10 -0500 |
commit | 0c89854da1893c9d9d5da1994bea69df31fc2a6f (patch) | |
tree | 15e94706b415d1d12820a6d9e576bf9df42cbc07 /src/nvim/eval/funcs.c | |
parent | 3d948a4dc4b2cd3c8d3ac497caf3dfe25adfb90d (diff) | |
download | rneovim-0c89854da1893c9d9d5da1994bea69df31fc2a6f.tar.gz rneovim-0c89854da1893c9d9d5da1994bea69df31fc2a6f.tar.bz2 rneovim-0c89854da1893c9d9d5da1994bea69df31fc2a6f.zip |
feat(terminal): close shell terminals automatically
When starting a terminal buffer that uses the default value of &shell
(e.g. when using `:terminal` or `termopen([&shell])`), automatically
close the buffer if the shell exits without an error.
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 177f64ebba..70e687ce73 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -8502,6 +8502,16 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) channel_terminal_open(curbuf, chan); channel_create_event(chan, NULL); + + do_cmdline_cmd("augroup nvim_terminal_close"); + do_cmdline_cmd("autocmd! TermClose <buffer> " + " if !v:event.status |" + " let info = nvim_get_chan_info(&channel) |" + " if info.argv ==# [&shell] |" + " exec 'bdelete! ' .. expand('<abuf>') |" + " endif |" + " endif"); + do_cmdline_cmd("augroup END"); } /// "timer_info([timer])" function |