refactor(git): drive :G dispatch from buffer content
This commit is contained in:
+17
-5
@@ -2,16 +2,19 @@ local M = {}
|
||||
|
||||
---@class ow.Git.Util.ScratchOpts
|
||||
---@field name string?
|
||||
---@field bufhidden ("hide"|"wipe")?
|
||||
---@field bufhidden ("hide"|"wipe"|"delete")?
|
||||
---@field buftype ("nofile"|"acwrite"|"nowrite")?
|
||||
---@field modifiable boolean?
|
||||
|
||||
---@param buf integer
|
||||
---@param opts ow.Git.Util.ScratchOpts
|
||||
local function setup_scratch(buf, opts)
|
||||
vim.bo[buf].buftype = "nofile"
|
||||
function M.setup_scratch(buf, opts)
|
||||
vim.bo[buf].buftype = opts.buftype or "nofile"
|
||||
vim.bo[buf].bufhidden = opts.bufhidden or "wipe"
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].modifiable = opts.modifiable == true
|
||||
vim.bo[buf].modified = false
|
||||
vim.bo[buf].buflisted = false
|
||||
if opts.name then
|
||||
pcall(vim.api.nvim_buf_set_name, buf, opts.name)
|
||||
end
|
||||
@@ -52,7 +55,7 @@ end
|
||||
function M.new_scratch(opts)
|
||||
opts = opts or {}
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
setup_scratch(buf, opts)
|
||||
M.setup_scratch(buf, opts)
|
||||
return buf, M.place_buf(buf, opts.split)
|
||||
end
|
||||
|
||||
@@ -188,6 +191,15 @@ end
|
||||
---@field silent boolean?
|
||||
---@field on_done fun(stdout: string?)?
|
||||
|
||||
---@param args string[]
|
||||
---@param opts ow.Git.Util.ExecOpts?
|
||||
---@return string?
|
||||
function M.git(args, opts)
|
||||
local cmd = { "git" }
|
||||
vim.list_extend(cmd, args)
|
||||
return M.exec(cmd, opts)
|
||||
end
|
||||
|
||||
---@param cmd string[]
|
||||
---@param opts ow.Git.Util.ExecOpts?
|
||||
---@return string?
|
||||
|
||||
Reference in New Issue
Block a user