diff --git a/lua/kitty-scrollback/kitty_commands.lua b/lua/kitty-scrollback/kitty_commands.lua index 67f0ef62..44adcbe9 100644 --- a/lua/kitty-scrollback/kitty_commands.lua +++ b/lua/kitty-scrollback/kitty_commands.lua @@ -146,7 +146,7 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb) -- set the shell used for termopen to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc) vim.o.shell = 'sh' - vim.fn.termopen(full_cmd, { + local success, error = pcall(vim.fn.termopen, full_cmd, { stdout_buffered = true, stderr_buffered = true, on_stdout = function(_, data) @@ -210,6 +210,12 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb) end end, }) + if not success then + display_error(full_cmd, { + entrypoint = 'termopen() :: pcall(vim.fn.termopen) error returned', + stderr = error or nil, + }) + end -- restore the original shell after processing termopen vim.o.shell = p.orig_options.shell diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index e7120598..ed044f61 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -312,7 +312,15 @@ end M.launch = function() local kitty_data = p.kitty_data vim.schedule(function() - p.bufid = vim.api.nvim_get_current_buf() + local buf_lines = vim.api.nvim_buf_get_lines(0, 0, 1, false) + local no_buf_content = vim.api.nvim_buf_line_count(0) == 1 and buf_lines[1] == '' + if no_buf_content then + p.bufid = vim.api.nvim_get_current_buf() + else + -- buffer must be empty for termopen, dashboard plugins may write to the first buffer before kitty-scrollback.nvim loads + p.bufid = vim.api.nvim_create_buf(true, true) + vim.api.nvim_set_current_buf(p.bufid) + end ksb_autocmds.load_autocmds()