mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(picker.preview): allow passing additional args to the git preview command
This commit is contained in:
parent
92312295a7
commit
910437f145
2 changed files with 15 additions and 22 deletions
|
@ -163,6 +163,7 @@ local defaults = {
|
|||
previewers = {
|
||||
git = {
|
||||
native = false, -- use native (terminal) or Neovim for previewing git diffs and commits
|
||||
args = {}, -- additional arguments passed to the git command. Useful to set pager options usin `-c ...`
|
||||
},
|
||||
file = {
|
||||
max_size = 1024 * 1024, -- 1MB
|
||||
|
|
|
@ -276,13 +276,19 @@ function M.git_show(ctx)
|
|||
M.cmd(cmd, ctx, { ft = not native and "git" or nil })
|
||||
end
|
||||
|
||||
---@param ctx snacks.picker.preview.ctx
|
||||
local function git(ctx, ...)
|
||||
local ret = { "git", "-c", "delta." .. vim.o.background .. "=true" }
|
||||
vim.list_extend(ret, ctx.picker.opts.previewers.git.args or {})
|
||||
vim.list_extend(ret, { ... })
|
||||
return ret
|
||||
end
|
||||
|
||||
---@param ctx snacks.picker.preview.ctx
|
||||
function M.git_log(ctx)
|
||||
local native = ctx.picker.opts.previewers.git.native
|
||||
local cmd = {
|
||||
"git",
|
||||
"-c",
|
||||
"delta." .. vim.o.background .. "=true",
|
||||
local cmd = git(
|
||||
ctx,
|
||||
"log",
|
||||
"--pretty=format:%h %s (%ch)",
|
||||
"--abbrev-commit",
|
||||
|
@ -291,8 +297,8 @@ function M.git_log(ctx)
|
|||
"--color=never",
|
||||
"--no-show-signature",
|
||||
"--no-patch",
|
||||
ctx.item.commit,
|
||||
}
|
||||
ctx.item.commit
|
||||
)
|
||||
if not native then
|
||||
table.insert(cmd, 2, "--no-pager")
|
||||
end
|
||||
|
@ -321,13 +327,7 @@ end
|
|||
---@param ctx snacks.picker.preview.ctx
|
||||
function M.git_diff(ctx)
|
||||
local native = ctx.picker.opts.previewers.git.native
|
||||
local cmd = {
|
||||
"git",
|
||||
"-c",
|
||||
"delta." .. vim.o.background .. "=true",
|
||||
"diff",
|
||||
"HEAD",
|
||||
}
|
||||
local cmd = git(ctx, "diff", "HEAD")
|
||||
if ctx.item.file then
|
||||
vim.list_extend(cmd, { "--", ctx.item.file })
|
||||
end
|
||||
|
@ -340,15 +340,7 @@ end
|
|||
---@param ctx snacks.picker.preview.ctx
|
||||
function M.git_stash(ctx)
|
||||
local native = ctx.picker.opts.previewers.git.native
|
||||
local cmd = {
|
||||
"git",
|
||||
"-c",
|
||||
"delta." .. vim.o.background .. "=true",
|
||||
"stash",
|
||||
"show",
|
||||
"--patch",
|
||||
ctx.item.stash,
|
||||
}
|
||||
local cmd = git(ctx, "stash", "show", "--patch", ctx.item.stash)
|
||||
if not native then
|
||||
table.insert(cmd, 2, "--no-pager")
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue