1
0
Fork 0

rework toggleterm stuff

This commit is contained in:
Luca Bilke 2024-01-28 17:30:35 +01:00
commit a6675310b2
4 changed files with 66 additions and 29 deletions
.config/nvim/lua

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