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 {
|
return { -- simple programmable terminal toggling for nvim
|
||||||
-- simpler, programmable and multiple terminal toggling for nvim
|
|
||||||
{
|
{
|
||||||
"akinsho/nvim-toggleterm.lua",
|
"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()
|
config = function()
|
||||||
require("toggleterm").setup({
|
require("toggleterm").setup({
|
||||||
open_mapping = [[<leader>=]],
|
open_mapping = [[<leader>tt]],
|
||||||
insert_mappings = false, -- don't map the key in insert mode
|
insert_mappings = false, -- don't map the key in insert mode
|
||||||
terminal_mappings = false,
|
terminal_mappings = false,
|
||||||
})
|
})
|
||||||
|
|
||||||
local Terminal = require("toggleterm.terminal").Terminal
|
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)
|
local function custom_term_set_toggle_key(term)
|
||||||
vim.keymap.set("t", "<C-\\>", function()
|
vim.keymap.set("t", "<C-\\>", function()
|
||||||
term:toggle()
|
term:toggle()
|
||||||
end, { silent = true, buffer = true })
|
end, { silent = true, buffer = true, desc = "terminal" })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create python window
|
local custom_term_default_style = function(cmd)
|
||||||
local function get_python_cmd()
|
return {
|
||||||
if vim.fn.executable("py") then
|
cmd = cmd,
|
||||||
return "py"
|
hidden = true,
|
||||||
end
|
direction = "float",
|
||||||
if vim.fn.executable("ptipython") then
|
float_opts = { border = "curved" },
|
||||||
return "ptipython"
|
on_open = custom_term_set_toggle_key,
|
||||||
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
|
end
|
||||||
local terms = {
|
local terms = {
|
||||||
lazygit = Terminal:new({
|
lazygit = Terminal:new(custom_term_default_style("lazygit")),
|
||||||
cmd = "lazygit",
|
python = Terminal:new(custom_term_default_style(function()
|
||||||
hidden = true,
|
for _, exec in pairs({ "py", "ptipython", "ipython", "ptpython", "python" }) do
|
||||||
direction = "float",
|
if vim.fn.executable(exec) > 0 then
|
||||||
float_opts = { border = "curved" },
|
return exec
|
||||||
on_open = custom_term_set_toggle_key,
|
end
|
||||||
}),
|
end
|
||||||
python = Terminal:new({
|
end)),
|
||||||
cmd = get_python_cmd(),
|
euporie = Terminal:new(custom_term_default_style(function()
|
||||||
hidden = true,
|
local kernel = vim.b.sessionfile
|
||||||
direction = "float",
|
if kernel then
|
||||||
float_opts = { border = "curved" },
|
return "euporie-console --connection-file '" .. kernel .. "'"
|
||||||
on_open = custom_term_set_toggle_key,
|
end
|
||||||
}),
|
return "euporie-console"
|
||||||
|
end)),
|
||||||
}
|
}
|
||||||
-- create a lazygit window with the lazygit command
|
-- have user decide between floating or split
|
||||||
local function toggle_custom_term(term, bang, vertsize)
|
local function toggle_split_or_float(term, bang, vertsize)
|
||||||
vertsize = vertsize or vim.o.columns * 0.4
|
vertsize = vertsize or vim.o.columns * 0.4
|
||||||
if not bang then
|
if not bang then
|
||||||
term.direction = "float"
|
term.direction = "float"
|
||||||
|
|
@ -74,30 +60,25 @@ return {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _Pythonterm_toggle(opts)
|
vim.api.nvim_create_user_command("Lazygit", function(opts)
|
||||||
toggle_custom_term(terms.python, opts.bang)
|
toggle_split_or_float(terms.lazygit, opts.bang, vim.o.columns * 0.6)
|
||||||
end
|
end, { desc = "Toggle floating Lazygit terminal", bang = true })
|
||||||
local function _Lazygit_toggle(opts)
|
vim.api.nvim_create_user_command("Pythonterm", function(opts)
|
||||||
toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6)
|
toggle_split_or_float(terms.python, opts.bang)
|
||||||
end
|
end, { desc = "Toggle floating Python terminal", bang = true })
|
||||||
|
vim.api.nvim_create_user_command("Euporieterm", function(opts)
|
||||||
vim.api.nvim_create_user_command(
|
toggle_split_or_float(terms.euporie, opts.bang)
|
||||||
"Lazygit",
|
end, { desc = "Toggle floating Euporie terminal", bang = true })
|
||||||
_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,
|
end,
|
||||||
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
|
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm", "Euporieterm" },
|
||||||
keys = {
|
keys = {
|
||||||
{ "<leader>sg", ":Lazygit<cr>", desc = "git floating" },
|
{ "<leader>tt", ":ToggleTerm<cr>", desc = "terminal" },
|
||||||
{ "<leader>sG", ":Lazygit!<cr>", desc = "git buffer" },
|
{ "<leader>tg", ":Lazygit<cr>", desc = "git floating" },
|
||||||
{ "<leader>sp", ":Pythonterm<cr>", desc = "python floating" },
|
{ "<leader>tG", ":Lazygit!<cr>", desc = "git buffer" },
|
||||||
{ "<leader>sP", ":Pythonterm!<cr>", desc = "python 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