rework toggleterm stuff
This commit is contained in:
parent
5ab47e55c9
commit
a6675310b2
4 changed files with 66 additions and 29 deletions
.config/nvim/lua
|
@ -148,7 +148,7 @@ if f.is_available("gitsigns.nvim") then
|
||||||
end
|
end
|
||||||
|
|
||||||
if f.is_available("lf.nvim") then
|
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
|
end
|
||||||
|
|
||||||
if f.is_available("mason.nvim") then
|
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"
|
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
|
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>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>th"] = { "<Cmd>ToggleTerm direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
|
||||||
maps.n["<leader>tv"] = { "<Cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" }
|
maps.n["<C-z>"] = { "<Cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
|
||||||
maps.n["<F7>"] = { "<Cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
|
maps.t["<C-z>"] = maps.n["<F7>"]
|
||||||
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>"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if f.is_available "nvim-dap" then
|
if f.is_available "nvim-dap" then
|
||||||
|
|
|
@ -120,24 +120,33 @@ function M.toggle_term_cmd(opts)
|
||||||
terms[opts.cmd][num]:toggle()
|
terms[opts.cmd][num]:toggle()
|
||||||
end
|
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)
|
function M.file_worktree(file, worktrees)
|
||||||
worktrees = worktrees or vim.g.git_worktrees
|
worktrees = worktrees or vim.g.git_worktrees
|
||||||
if not worktrees then return end
|
if not worktrees then return end
|
||||||
file = file or vim.fn.expand("%")
|
file = file or vim.fn.expand "%"
|
||||||
for _, worktree in ipairs(worktrees) do
|
for _, worktree in ipairs(worktrees) do
|
||||||
local r = vim.fn.system({
|
if
|
||||||
"git",
|
M.cmd({
|
||||||
"--work-tree",
|
"git",
|
||||||
worktree.toplevel,
|
"--work-tree",
|
||||||
"--git-dir",
|
worktree.toplevel,
|
||||||
worktree.gitdir,
|
"--git-dir",
|
||||||
"ls-files",
|
worktree.gitdir,
|
||||||
"--error-unmatch",
|
"ls-files",
|
||||||
file
|
"--error-unmatch",
|
||||||
---@diagnostic disable-next-line: undefined-field
|
file,
|
||||||
}):wait()
|
}, false)
|
||||||
if r.code == 0 then
|
then
|
||||||
return worktree
|
return worktree
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
local M = { "lmburns/lf.nvim" }
|
local M = { "lmburns/lf.nvim" }
|
||||||
|
local tt = require("plugins.misc.toggleterm").opts
|
||||||
|
|
||||||
M.depends = { "toggleterm.nvim" }
|
M.depends = { "toggleterm.nvim" }
|
||||||
|
|
||||||
M.cmd = { "Lf" }
|
M.cmd = { "Lf" }
|
||||||
|
|
||||||
M.opts = {
|
M.opts = {
|
||||||
|
default_actions = {
|
||||||
|
["<C-t>"] = "",
|
||||||
|
["<C-x>"] = "",
|
||||||
|
["<C-v>"] = "",
|
||||||
|
["<C-o>"] = "",
|
||||||
|
},
|
||||||
mappings = false,
|
mappings = false,
|
||||||
winblend = 5,
|
width = tt.float_opts.width,
|
||||||
border = "rounded",
|
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
|
return M
|
||||||
|
|
|
@ -3,9 +3,31 @@ local M = { "akinsho/toggleterm.nvim" }
|
||||||
M.cmd = { "ToggleTerm", "TermExec" }
|
M.cmd = { "ToggleTerm", "TermExec" }
|
||||||
|
|
||||||
M.opts = {
|
M.opts = {
|
||||||
shade_terminals = false,
|
size = function(term)
|
||||||
open_mapping = false,
|
if term.direction == "horizontal" then
|
||||||
direction = "horizontal",
|
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()
|
on_create = function()
|
||||||
vim.opt.foldcolumn = "0"
|
vim.opt.foldcolumn = "0"
|
||||||
vim.opt.signcolumn = "no"
|
vim.opt.signcolumn = "no"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue