From 9a79b23a526b32ed6559efb48a494e16fd1f1a55 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sat, 12 Apr 2025 12:54:43 +0200 Subject: [PATCH] Neovim: Add the terminal module --- .config/nvim/lua/terminal.lua | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .config/nvim/lua/terminal.lua diff --git a/.config/nvim/lua/terminal.lua b/.config/nvim/lua/terminal.lua new file mode 100644 index 0000000..28ba8b9 --- /dev/null +++ b/.config/nvim/lua/terminal.lua @@ -0,0 +1,36 @@ +-- Module for managing popup terminal + +local M = {} + +M.persistent_term = nil + +local create_command = function(name, command) + if not name or type(name) ~= "string" then return end + + vim.api.nvim_create_user_command(name, function() + local cmd = type(command) == "function" and command() or command + M.send_cmd_to_term(cmd) + end, {}) +end + +M.setup = function() + -- Setup keybinds + require("keybinds").toggleterm_nvim() + + create_command("RunScript", "sleep 2 && ls /") + create_command("ScanScript", function() + local file_path = vim.fn.expand("%:p") + LOG(file_path) + + return "ls" + end) +end + +M.send_cmd_to_term = function(cmd) + local term = require("toggleterm.terminal").Terminal + local default = term:new({ id = 1 }) + if not default:is_open() then default:open() end + default:send(cmd) +end + +return M