From b2e0621d1238c3f3de44c3150d6df7aca4be1427 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 14 Aug 2024 12:03:23 +0200 Subject: [PATCH] wezterm: Decouple toggleterm plugin from ui module For now lives in a 'terminal.lua' module instead. --- nvim/.config/nvim/lua/plugins/terminal.lua | 103 +++++++++++++++++++++ nvim/.config/nvim/lua/plugins/ui.lua | 101 -------------------- 2 files changed, 103 insertions(+), 101 deletions(-) create mode 100644 nvim/.config/nvim/lua/plugins/terminal.lua diff --git a/nvim/.config/nvim/lua/plugins/terminal.lua b/nvim/.config/nvim/lua/plugins/terminal.lua new file mode 100644 index 0000000..ac97546 --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/terminal.lua @@ -0,0 +1,103 @@ +return { + -- simpler, programmable and multiple terminal toggling for nvim + { + "akinsho/nvim-toggleterm.lua", + config = function() + require("toggleterm").setup({ + open_mapping = [[=]], + insert_mappings = false, -- don't map the key in insert mode + terminal_mappings = false, + }) + + local Terminal = require("toggleterm.terminal").Terminal + + -- need to disable indentlines since they obscure first line of terminal + if require("core.util").is_available("mini.nvim") then + vim.api.nvim_create_autocmd({ "TermOpen" }, { + pattern = "*", + callback = function() + vim.b.miniindentscope_disable = true + end, + }) + end + + local function custom_term_set_toggle_key(term) + vim.keymap.set("t", "", function() + term:toggle() + end, { silent = true, buffer = true }) + end + + -- create python window + local function get_python_cmd() + if vim.fn.executable("py") then + return "py" + end + if vim.fn.executable("ptipython") then + return "ptipython" + end + if vim.fn.executable("ipython") then + return "ipython" + end + if vim.fn.executable("ptpython") then + return "ptpython" + end + if vim.fn.executable("python") then + return "python" + end + end + local terms = { + lazygit = Terminal:new({ + cmd = "lazygit", + hidden = true, + direction = "float", + float_opts = { border = "curved" }, + on_open = custom_term_set_toggle_key, + }), + python = Terminal:new({ + cmd = get_python_cmd(), + hidden = true, + direction = "float", + float_opts = { border = "curved" }, + on_open = custom_term_set_toggle_key, + }), + } + -- create a lazygit window with the lazygit command + local function toggle_custom_term(term, bang, vertsize) + vertsize = vertsize or vim.o.columns * 0.4 + if not bang then + term.direction = "float" + term:toggle() + else + term.direction = "vertical" + term:resize(vertsize) + term:toggle() + end + end + + local function _Pythonterm_toggle(opts) + toggle_custom_term(terms.python, opts.bang) + end + local function _Lazygit_toggle(opts) + toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6) + end + + vim.api.nvim_create_user_command( + "Lazygit", + _Lazygit_toggle, + { desc = "Toggle floating Lazygit terminal", bang = true } + ) + vim.api.nvim_create_user_command( + "Pythonterm", + _Pythonterm_toggle, + { desc = "Toggle floating Python terminal", bang = true } + ) + end, + cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" }, + keys = { + { "sg", ":Lazygit", desc = "git floating" }, + { "sG", ":Lazygit!", desc = "git buffer" }, + { "sp", ":Pythonterm", desc = "python floating" }, + { "sP", ":Pythonterm!", desc = "python buffer" }, + }, + }, +} diff --git a/nvim/.config/nvim/lua/plugins/ui.lua b/nvim/.config/nvim/lua/plugins/ui.lua index ce6539e..b72d249 100644 --- a/nvim/.config/nvim/lua/plugins/ui.lua +++ b/nvim/.config/nvim/lua/plugins/ui.lua @@ -174,105 +174,4 @@ return { }, }, }, - -- simpler, programmable and multiple terminal toggling for nvim - { - "akinsho/nvim-toggleterm.lua", - config = function() - require("toggleterm").setup({ - open_mapping = [[=]], - insert_mappings = false, -- don't map the key in insert mode - terminal_mappings = false, - }) - - local Terminal = require("toggleterm.terminal").Terminal - - -- need to disable indentlines since they obscure first line of terminal - if require("core.util").is_available("mini.nvim") then - vim.api.nvim_create_autocmd({ "TermOpen" }, { - pattern = "*", - callback = function() - vim.b.miniindentscope_disable = true - end, - }) - end - - local function custom_term_set_toggle_key(term) - vim.keymap.set("t", "", function() - term:toggle() - end, { silent = true, buffer = true }) - end - - -- create python window - local function get_python_cmd() - if vim.fn.executable("py") then - return "py" - end - if vim.fn.executable("ptipython") then - return "ptipython" - end - if vim.fn.executable("ipython") then - return "ipython" - end - if vim.fn.executable("ptpython") then - return "ptpython" - end - if vim.fn.executable("python") then - return "python" - end - end - local terms = { - lazygit = Terminal:new({ - cmd = "lazygit", - hidden = true, - direction = "float", - float_opts = { border = "curved" }, - on_open = custom_term_set_toggle_key, - }), - python = Terminal:new({ - cmd = get_python_cmd(), - hidden = true, - direction = "float", - float_opts = { border = "curved" }, - on_open = custom_term_set_toggle_key, - }), - } - -- create a lazygit window with the lazygit command - local function toggle_custom_term(term, bang, vertsize) - vertsize = vertsize or vim.o.columns * 0.4 - if not bang then - term.direction = "float" - term:toggle() - else - term.direction = "vertical" - term:resize(vertsize) - term:toggle() - end - end - - local function _Pythonterm_toggle(opts) - toggle_custom_term(terms.python, opts.bang) - end - local function _Lazygit_toggle(opts) - toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6) - end - - vim.api.nvim_create_user_command( - "Lazygit", - _Lazygit_toggle, - { desc = "Toggle floating Lazygit terminal", bang = true } - ) - vim.api.nvim_create_user_command( - "Pythonterm", - _Pythonterm_toggle, - { desc = "Toggle floating Python terminal", bang = true } - ) - end, - cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" }, - keys = { - { "sg", ":Lazygit", desc = "git floating" }, - { "sG", ":Lazygit!", desc = "git buffer" }, - { "sp", ":Pythonterm", desc = "python floating" }, - { "sP", ":Pythonterm!", desc = "python buffer" }, - }, - }, }