refactor(git): convert blocking subprocess calls to async
This commit is contained in:
@@ -25,6 +25,33 @@ function M.head(path)
|
||||
return repo.head(path)
|
||||
end
|
||||
|
||||
---@class ow.Git.NewScratchOpts
|
||||
---@field name string?
|
||||
---@field bufhidden ("hide"|"wipe")? defaults to "hide"
|
||||
---@field split ("above"|"below"|"left"|"right")? defaults to splitbelow-aware horizontal
|
||||
|
||||
---Open a split with a fresh non-modifiable scratch buffer. Default split
|
||||
---direction is horizontal, honouring `splitbelow`. Caller flips
|
||||
---`modifiable`, fills the buffer, and sets `filetype` once content lands.
|
||||
---@param opts ow.Git.NewScratchOpts?
|
||||
---@return integer buf
|
||||
---@return integer win
|
||||
function M.new_scratch(opts)
|
||||
opts = opts or {}
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.bo[buf].buftype = "nofile"
|
||||
vim.bo[buf].bufhidden = opts.bufhidden or "hide"
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].modified = false
|
||||
if opts.name then
|
||||
pcall(vim.api.nvim_buf_set_name, buf, opts.name)
|
||||
end
|
||||
local split = opts.split or (vim.o.splitbelow and "below" or "above")
|
||||
local win = vim.api.nvim_open_win(buf, true, { split = split })
|
||||
return buf, win
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
for name, link in pairs(HIGHLIGHTS) do
|
||||
vim.api.nvim_set_hl(0, name, { link = link, default = true })
|
||||
|
||||
Reference in New Issue
Block a user