I am trying to create a function that will open a single interactive command (called doc) in a terminal. I have it basically working with this function:
function()
vim.cmd.te()
local keys = vim.api.nvim_replace_termcodes("idoc<cr>", true, false, true)
vim.api.nvim_feedkeys(keys, "t", false)
end
The problem is that it takes a while to open, because of my .zshrc. And, after I quit the command, there is still a terminal running. This would be fixed if I could pass the flags --no-rcs and --onecmd to Zsh when I first ran :terminal. Is there a way to do this? And if not, is there some other way to fix the problems?
How about jobwait? The returned value of termopen is same as jobstart, which represents a job ID. We can use the jobwait function to wait for a job exits with the job ID. See :help jobstart() and :jobwait() for details.
Instead of jobwait, just pass an on_exit handler to either termopen or jobstart. To automatically close the terminal and not wait for confirmation on exit code 0, you can have:
vim.fn.termopen({"zsh", "--onecmd", "--no-rcs"}, { on_exit = function() vim.api.nvim_input("<Cr>") end })
Although running that I just get a blank screen, I’ve only ever done it for interactive commands like “python” or some such.