nvim: Improve custom toggle terms
Added euporia term to split it from other python variations. Fixed python command selection. Improved mapping and which key display. Removed indentline settings since that is responsibility of indentline.
This commit is contained in:
parent
101937a8c2
commit
99eada00b8
1 changed files with 50 additions and 69 deletions
|
|
@ -1,68 +1,54 @@
|
|||
return {
|
||||
-- simpler, programmable and multiple terminal toggling for nvim
|
||||
return { -- simple programmable terminal toggling for nvim
|
||||
{
|
||||
"akinsho/nvim-toggleterm.lua",
|
||||
init = function(_)
|
||||
if require("core.util").is_available("which-key") then
|
||||
require("which-key").add({ "<leader>t", group = "terminal" })
|
||||
end
|
||||
end,
|
||||
config = function()
|
||||
require("toggleterm").setup({
|
||||
open_mapping = [[<leader>=]],
|
||||
open_mapping = [[<leader>tt]],
|
||||
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", "<C-\\>", function()
|
||||
term:toggle()
|
||||
end, { silent = true, buffer = true })
|
||||
end, { silent = true, buffer = true, desc = "terminal" })
|
||||
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
|
||||
local custom_term_default_style = function(cmd)
|
||||
return {
|
||||
cmd = cmd,
|
||||
hidden = true,
|
||||
direction = "float",
|
||||
float_opts = { border = "curved" },
|
||||
on_open = custom_term_set_toggle_key,
|
||||
}
|
||||
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,
|
||||
}),
|
||||
lazygit = Terminal:new(custom_term_default_style("lazygit")),
|
||||
python = Terminal:new(custom_term_default_style(function()
|
||||
for _, exec in pairs({ "py", "ptipython", "ipython", "ptpython", "python" }) do
|
||||
if vim.fn.executable(exec) > 0 then
|
||||
return exec
|
||||
end
|
||||
end
|
||||
end)),
|
||||
euporie = Terminal:new(custom_term_default_style(function()
|
||||
local kernel = vim.b.sessionfile
|
||||
if kernel then
|
||||
return "euporie-console --connection-file '" .. kernel .. "'"
|
||||
end
|
||||
return "euporie-console"
|
||||
end)),
|
||||
}
|
||||
-- create a lazygit window with the lazygit command
|
||||
local function toggle_custom_term(term, bang, vertsize)
|
||||
-- have user decide between floating or split
|
||||
local function toggle_split_or_float(term, bang, vertsize)
|
||||
vertsize = vertsize or vim.o.columns * 0.4
|
||||
if not bang then
|
||||
term.direction = "float"
|
||||
|
|
@ -74,30 +60,25 @@ return {
|
|||
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 }
|
||||
)
|
||||
vim.api.nvim_create_user_command("Lazygit", function(opts)
|
||||
toggle_split_or_float(terms.lazygit, opts.bang, vim.o.columns * 0.6)
|
||||
end, { desc = "Toggle floating Lazygit terminal", bang = true })
|
||||
vim.api.nvim_create_user_command("Pythonterm", function(opts)
|
||||
toggle_split_or_float(terms.python, opts.bang)
|
||||
end, { desc = "Toggle floating Python terminal", bang = true })
|
||||
vim.api.nvim_create_user_command("Euporieterm", function(opts)
|
||||
toggle_split_or_float(terms.euporie, opts.bang)
|
||||
end, { desc = "Toggle floating Euporie terminal", bang = true })
|
||||
end,
|
||||
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
|
||||
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm", "Euporieterm" },
|
||||
keys = {
|
||||
{ "<leader>sg", ":Lazygit<cr>", desc = "git floating" },
|
||||
{ "<leader>sG", ":Lazygit!<cr>", desc = "git buffer" },
|
||||
{ "<leader>sp", ":Pythonterm<cr>", desc = "python floating" },
|
||||
{ "<leader>sP", ":Pythonterm!<cr>", desc = "python buffer" },
|
||||
{ "<leader>tt", ":ToggleTerm<cr>", desc = "terminal" },
|
||||
{ "<leader>tg", ":Lazygit<cr>", desc = "git floating" },
|
||||
{ "<leader>tG", ":Lazygit!<cr>", desc = "git buffer" },
|
||||
{ "<leader>tp", ":Pythonterm<cr>", desc = "python floating" },
|
||||
{ "<leader>tP", ":Pythonterm!<cr>", desc = "python buffer" },
|
||||
{ "<leader>te", ":Euporieterm<cr>", desc = "euporie floating" },
|
||||
{ "<leader>tE", ":Euporieterm!<cr>", desc = "euporie buffer" },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue