From 7b7df6a34332493a80003d92fc3a632f54e4b843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Sat, 11 Oct 2025 18:52:51 +0200 Subject: [PATCH] feat: add simple script for managing terminals --- plugin/geterm.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugin/geterm.lua diff --git a/plugin/geterm.lua b/plugin/geterm.lua new file mode 100644 index 0000000..c9195f2 --- /dev/null +++ b/plugin/geterm.lua @@ -0,0 +1,33 @@ +---@class TermBuf +---@field buf_id integer +---@field term_id integer + +---@type table +local state = {} + +---@param n integer +local function get_or_create_term(n) + if state[n] ~= nil then + vim.api.nvim_win_set_buf(0, state[n].buf_id) + return + end + + vim.cmd.terminal() + local buf_id = vim.api.nvim_get_current_buf() + local term_id = vim.b.terminal_job_id + vim.cmd.startinsert() + + state[n] = { buf_id = buf_id, term_id = term_id } +end + +---@param f function +local function count_fn(f) + local function wrap(...) + local count = vim.v.count + return f(count, arg) + end + + return wrap +end + +vim.keymap.set("n", "tn", count_fn(get_or_create_term))