diff --git a/lua/pika/core/keymaps.lua b/lua/pika/core/keymaps.lua index 0a54da3..e24df43 100644 --- a/lua/pika/core/keymaps.lua +++ b/lua/pika/core/keymaps.lua @@ -62,20 +62,24 @@ map("n", "R", [[:%s/\<\>//gI]]) map("n", "sv", "v", { desc = "Split window vertically" }) -- split window vertically map("n", "sh", "s", { desc = "Split window horizontally" }) -- split window horizontally -vim.keymap.set({ "n", "v" }, "tt", function() +vim.keymap.set({ "n", "i" }, "tt", function() -- Frage den Shell-Command ab vim.ui.input({ prompt = "Shell Command: " }, function(cmd) if cmd == nil or cmd == "" then return end - local handle = io.popen(cmd) - local result = handle:read("*a") - handle:close() + local result = vim.fn.system(cmd) + local exit_code = vim.v.shell_error + + if exit_code ~= 0 then + vim.notify("Shell Error:\n" .. result, vim.log.levels.ERROR, { title = "Shell Command Failed" }) + return + end local lines = vim.split(result, "\n", { trimempty = true }) - -- Einfügen an Cursor-Position + -- Insert at cursor position local row, col = unpack(vim.api.nvim_win_get_cursor(0)) vim.api.nvim_buf_set_lines(0, row, row, false, lines) end)