1
0
Fork 0

rework toggleterm stuff

This commit is contained in:
Luca Bilke 2024-01-28 17:30:35 +01:00
parent 5ab47e55c9
commit a6675310b2
4 changed files with 66 additions and 29 deletions

View file

@ -148,7 +148,7 @@ if f.is_available("gitsigns.nvim") then
end
if f.is_available("lf.nvim") then
maps.n["<Leader>e"] = { "<Cmd>Lf<CR>", desc = "File manager" }
maps.n["<Leader>e"] = { require("lf").start, desc = "File manager" }
end
if f.is_available("mason.nvim") then
@ -254,15 +254,9 @@ if f.is_available("toggleterm.nvim") then
local python = vim.fn.executable "python" == 1 and "python" or vim.fn.executable "python3" == 1 and "python3"
if python then maps.n["<leader>tp"] = { function() f.toggle_term_cmd(python) end, desc = "ToggleTerm python" } end
maps.n["<leader>tf"] = { "<Cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" }
maps.n["<leader>th"] = { "<Cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
maps.n["<leader>tv"] = { "<Cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" }
maps.n["<F7>"] = { "<Cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
maps.t["<F7>"] = maps.n["<F7>"]
-- TODO: Patch st: https://st.suckless.org/patches/fix_keyboard_input/
-- maps.n["<C-'>"] = maps.n["<F7>"]
-- maps.t["<C-'>"] = maps.t["<F7>"]
maps.n["<C-z>"] = maps.n["<F7>"]
maps.t["<C-z>"] = maps.t["<F7>"]
maps.n["<leader>th"] = { "<Cmd>ToggleTerm direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
maps.n["<C-z>"] = { "<Cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
maps.t["<C-z>"] = maps.n["<F7>"]
end
if f.is_available "nvim-dap" then

View file

@ -120,24 +120,33 @@ function M.toggle_term_cmd(opts)
terms[opts.cmd][num]:toggle()
end
-- TODO: test this
function M.cmd(cmd, show_error)
if type(cmd) == "string" then cmd = { cmd } end
local result = vim.fn.system(cmd)
local success = vim.api.nvim_get_vvar "shell_error" == 0
if not success and (show_error == nil or show_error) then
vim.api.nvim_err_writeln(("Error running command %s\nError message:\n%s"):format(table.concat(cmd, " "), result))
end
return success and result:gsub("[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]", "") or nil
end
function M.file_worktree(file, worktrees)
worktrees = worktrees or vim.g.git_worktrees
if not worktrees then return end
file = file or vim.fn.expand("%")
file = file or vim.fn.expand "%"
for _, worktree in ipairs(worktrees) do
local r = vim.fn.system({
"git",
"--work-tree",
worktree.toplevel,
"--git-dir",
worktree.gitdir,
"ls-files",
"--error-unmatch",
file
---@diagnostic disable-next-line: undefined-field
}):wait()
if r.code == 0 then
if
M.cmd({
"git",
"--work-tree",
worktree.toplevel,
"--git-dir",
worktree.gitdir,
"ls-files",
"--error-unmatch",
file,
}, false)
then
return worktree
end
end

View file

@ -1,13 +1,25 @@
local M = { "lmburns/lf.nvim" }
local tt = require("plugins.misc.toggleterm").opts
M.depends = { "toggleterm.nvim" }
M.cmd = { "Lf" }
M.opts = {
default_actions = {
["<C-t>"] = "",
["<C-x>"] = "",
["<C-v>"] = "",
["<C-o>"] = "",
},
mappings = false,
winblend = 5,
border = "rounded",
width = tt.float_opts.width,
height = tt.float_opts.height,
winblend = tt.float_opts.winblend,
direction = tt.direction,
border = tt.float_opts.border,
highlights = tt.highlights,
float_opts = tt.float_opts,
}
return M

View file

@ -3,9 +3,31 @@ local M = { "akinsho/toggleterm.nvim" }
M.cmd = { "ToggleTerm", "TermExec" }
M.opts = {
shade_terminals = false,
open_mapping = false,
direction = "horizontal",
size = function(term)
if term.direction == "horizontal" then
return vim.o.lines * 0.33
elseif term.direction == "vertical" then
return vim.o.colums * 0.33
end
end,
open_mapping = "<C-z>",
direction = "float",
highlights = {
Normal = { link = "Normal" },
NormalNC = { link = "NormalNC" },
NormalFloat = { link = "NormalFloat" },
FloatBorder = { link = "FloatBorder" },
StatusLine = { link = "StatusLine" },
StatusLineNC = { link = "StatusLineNC" },
WinBar = { link = "WinBar" },
WinBarNC = { link = "WinBarNC" },
},
float_opts = {
border = "curved",
winblend = 5,
width = function() return math.ceil(math.min(vim.o.columns, math.max(80, vim.o.columns - 20))) end,
height = function() return math.ceil(math.min(vim.o.lines, math.max(20, vim.o.lines - 10))) end,
},
on_create = function()
vim.opt.foldcolumn = "0"
vim.opt.signcolumn = "no"