diff --git a/symlinks/config/nvim/plugin/popupterm.lua b/symlinks/config/nvim/plugin/popupterm.lua new file mode 100644 index 0000000..d119878 --- /dev/null +++ b/symlinks/config/nvim/plugin/popupterm.lua @@ -0,0 +1,50 @@ +-- Popupterm - get a popup with terminal buffer +local popup = require("nui.popup") +local event = require("nui.utils.autocmd").event + +local last_term_win + +local function popup_terminal() + if last_term_win then + last_term_win:show() + return + end + + local win = popup({ + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + }) + + -- mount/open the component + win:mount() + + vim.cmd("edit term://" .. vim.env.SHELL) + + -- map keys + win:map("n", "", function(_) + win:hide() + end, { noremap = true }) + + -- unmount component when cursor leaves buffer + win:on(event.BufLeave, function() + win:hide() + end) + + win:on(event.BufDelete, function() + last_term_win = nil + end) + + last_term_win = win +end + +vim.api.nvim_create_user_command("PopupTerm", function() + popup_terminal() +end, {})